1756742 Members
2496 Online
108852 Solutions
New Discussion юеВ

Re: Redirection in csh

 
parmy_4
Occasional Contributor

Redirection in csh

Hi techies,
Could any one explain (or redirect) me to know more about Outpur redirection in C Shell. I want both error and regular output to be written into a file and should also display at the Standard Output.

Thanks in Advance,
-Parmy
6 REPLIES 6
Simon Hargrave
Honored Contributor

Re: Redirection in csh

csh is very bad for this kind of thing.

the nearest you can get is something like: -

touch log ; tail -f log & ; your_command >& log

This should give an idea of the inflexibilities of the csh, in various areas: -

http://www.ooblick.com/text/CshProgrammingConsideredHarmful.html
Mark Ellzey
Valued Contributor

Re: Redirection in csh

Parmy,

You can also use the 'tee' command. Check out man tee(1).

In my scripts, I'll check if it is interactive, and if so, then I'll pipe the output throught tee. In this way, the user gets to see the output on the screen, and the output is also being saved in a log file.

Something like this:

ls -l /etc | tee /tmp/logfile.log

Regards,
Mark
Simon Hargrave
Honored Contributor

Re: Redirection in csh

Only problem with tee is it doesn't capture stderr. In sh that's fine you can 2>&1, but not in csh.
Muthukumar_5
Honored Contributor

Re: Redirection in csh


Redirection can be done based on the output type weather on STDOUT (output mode ) and STDERR ( error mode).

File descriptor 1 is used for standard ouput and 2 is for standard error.
hostname 1> /tmp/hostname.file

hostname output will be redirected to /tmp/hostname.file

IF you want to write output and error in on same file then,

-- file.csh --
hostname
trr
--------------

# csh file.csh 1>/filenamewithpath 2>&1

It will redirect all output / error to that file or

# csh file.csh 1>/filenamewithpath 2>/filenamewithpath

You can also use aslike as,

# csh file.csh 1>>/filenamewithpath 2>>/filenamewithpath


Difference between >> and > is

>> - it will append contents or create new file and add more contents

> - it will create or make null the existing file

HTH.
+Muthu+
Easy to suggest when don't know about the problem!
Carlo Corthouts
Frequent Advisor

Re: Redirection in csh

You also can use the "tee" command for that.
Muthukumar_5
Honored Contributor

Re: Redirection in csh

hai,

another command be used for this as script

script test.log
hostname
uname -a
exit

cat test.log will contain your log informations there.

-muthu
Easy to suggest when don't know about the problem!