Is it possible to redirect all of the output of a Bourne shell script to somewhere, but with shell commands inside the script itself?
Redirecting the output of a single command is easy, but I want something more like this:
if [ ! -t 0 ]; then
# redirect all of my output to a file here
# rest of script...
# save stdout and stderr to file descriptors 3 and 4, then redirect them to "foo"
exec 3>&1 4>&2 >foo 2>&1
# restore stdout and stderr
exec 1>&3 2>&4
Send stdout to a file
exec > file
exec > file exec 2>&1
append both stdout and stderr to file
exec >> file exec 2>&1