redirect COPY of stdout to log file from within bash script itself

I know how to redirect stdout to a file:

exec > foo.log
echo test

this will put the ‘test’ into the foo.log file.

Now I want to redirect the output into the log file AND keep it on stdout

i.e. it can be done trivially from outside the script:

script | tee foo.log

but I want to do declare it within the script itself

I tried

exec | tee foo.log

but it didn’t work.

9 Answers
9

Leave a Comment