Send output to file from shell script

I am creating a script to run users. I need to redirect the output to a file that I create from a script (name-name-date).

I have all the parts except how to copy the output of the script from within the same script. All the examples I can find are called script and> it in the log, but this is not an option.

for -Alex-

+6
unix shell
source share
3 answers

Add the following to the beginning of the script:

exec &> output.txt 

This will cause the stdin and stderr commands in the rest of your script to go into output.txt .

+9
source share

exec in bash allows you to forever redirect FD (say stdout) to a file.

+1
source share

The shell that invokes the shell.

Let the first shell create a variable (name-name-date) and call the second shell, redirecting the output to a file.

0
source share

All Articles