Redirect stdout/stderr to a file globally

Hi

I am not if this is possible: is it possible in bach (or another shell) to redirect GLOBALLY the stdout/stderr channels to a file.

So, if I have a script

script.sh
cmd1
cmd2
cmd3

I want all stdout/stderr goes to a file. I know I can do:

./script.sh 1>file 2>&1

OR

script.sh
cmd1 1>>file 2>>&1
cmd2 1>>file 2>>&1
cmd3 1>>file 2>>&1

but, what I want to do, is something like

script.sh
stdout is now 'file'
stderr is now 'file'
cmd1
cmd2
cmd3

Why do I want to do that? I'm just curious :slight_smile:

Thanks a lot

Isi

PS: I guess that must be called 'channel duplication' or something like that

exec 1>std.out.file
exec 2>std.err.file 
# other code here ........
exit 

Awesome! :slight_smile:

Let's suppose I'm not inside a script, I am in a shell (so, I don't want to execute exit), how can I undo the redirect? Somehing like "exec 1>/dev/tty[n]"? How can I see where is stdout pointing (echo....) ?

Thanks a lot

Isi