The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 04-22-2009
islegmar islegmar is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 10
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 :-)

Thanks a lot

Isi

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