If you intend to use csh, you need to know the limitations. In this specific instance, see the very first section of Csh Programming Considered Harmful ... cheers, drl
[quote]
In a csh script, what happens when you run:
echo one
echo two 2>&1
[quote]
No difference at all, because no error message was generated!
If you ran:
tony@tony-laptop:~$ ls -l fred > /tmp/logfile
ls: cannot access fred: No such file or directory
tony@tony-laptop:~$ cat /tmp/logfile
Then the listing of fred (if it had existed) would have gone into /tmp/logfile, that is stdout, file handle 1.
The error message is sent to stderr, file handle 2, allowing the user to see it even though stdout was sent to a log file.
If you then run:
tony@tony-laptop:~$ ls -l fred > /tmp/logfile 2>&1
tony@tony-laptop:~$ cat /tmp/logfile
ls: cannot access fred: No such file or directory
tony@tony-laptop:~$
Then the 2>&1 has redirected stderr to stdout, stdout was sent to /tmp/logfile so the error message also goes to /tmp/logfile.
I have run the following script "s3" on Linux and Solaris. The string two is never displayed:
#!/bin/csh
ls -l /bin/csh
echo
echo one
echo two 2>&1
echo three
exit 0
producing:
% ./s3
one
three
The point is that "2>&1" does not work in the csh family as it does in the Bourne shell family. What happens is that a file named "1" is created with the content:
Sorry drl I was obviously thinking in Bourne shell mode, have not used C shell in anger since departing from SunOS! I must admit I can't see why anyone would script in C shell, it was a good interactive shell before Korn and Bash came along but it was never very good for scripting!