Le 03/12/2010 14:46, Payam Poursaied a écrit : > > Hi all, > I'm not sure this is a bug or please let me know the concept: > What is the difference between: > ls -R /etc/ 2>&1 1>/dev/null > and > ls -R /etc/ 1>/dev/null 2>&1 > > the second one redirect everything to /dev/null but the first one, still > prints errors (run as a non root user would unveil the problem) > it the order of arguments important? If yes, what is the idea/concept behind > this behavior?
I was confused by this for a long time and kept reading again and again the correct but *too long* answers others have posted, until I started using this *short* reading trick: 2>&1 1>/dev/null output2 := output1; output1 := NULL When you apply this from left to right it should be quite obvious why output2 is not NULL. And now you can finally understand things like this: exec 3>&1 4>&2 # save exec 1>/dev/null 2>&1 # .... discard everything ... exec 1>&3 2>&4 # restore