Monday, November 11, 2013

Be Aware Of the Shell You Are Using

I used to get this wired error when I was trying to redirect both stdout and stderr to a file. What I did was, 

    "ls > foo.log 2>&1"

If you search for output redirecting, all articles online would tell you this is correct. However my shell kept complaining "Ambiguous output redirect."

This is a csh/tcsh error message for which the correct redirection is supposed to be
    "ls >& foo.log"

So, apparently I was using a csh/tcsh, rather than BASH shell. The former was in BASH syntax.

To find out what shell you are using, type
    "ps -p $$" on whatever shell you are working on, it will tell you.