How to redirect the entire bash script within the script itself?

Asked

Viewed 203 times

1

I need to throw his output into a file instead of playing on the default output which is the screen but without me having to spell it out with the command >> in the terminal, I want the script itself to do this.

  • where I just run it and it already auto redirects itself? Can you be clearer? It was very confusing your question.

  • So, I want to play its output in a file instead of playing in the default output which is the screen but without me having to spell it out with the >> in the terminal,, I want the script itself to do this.

  • What you want is something like: echo $SHELL > /tmp/teste running within the script?

  • If that’s what I understand, you can redirect what you would do in the terminal inside the script itself, setting an output file to the commands instead of the standard output.

1 answer

3


Do it this way:

{
   #seus comandos bash aqui
} > output.txt 2>&1

NOTE: If you do not specify the output path, the file will be generated in the directory in which the bash script is.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.