hey all, I have repeatedly seen scripts containing the following syntax,
grep "hello" $myfile >> $log 2>&1
can anyone explain exactly what "2>&1" mean? THANK YOU
hey all, I have repeatedly seen scripts containing the following syntax,
grep "hello" $myfile >> $log 2>&1
can anyone explain exactly what "2>&1" mean? THANK YOU
Care to read the man pages ? See the section REDIRECTION under man sh.
while i am waiting other to help on my question, let me explain it to you !!
grep "hello" $myfile >> $log -----> all standard output will go into $log, except error which will output to your screen.
for this reason,we use 2>&1 ----> so that (2)=all error will go into (1)=standard output which you have already define as $log
so all output including error message wll all go into $log
Anyway man page will explain in more detail....
If you find man page not very interesting.These two links will give you idea about file descriptors (2>...>&1)
In unix 1 is defaut file descriptor for stdout and 2 is default file descriptor for stderr. So when you try redirecting on any of them you will redirect the stderr or stdout to a file or /dev/null.
regards
Apoorva Kumar