接下來,有趣的東西來了。根據「man bash」裡 REDIRECTION 段落裡的說明,重新導向的順序是由左至右。也就是說「>/dev/null 2>&1」會先處理「>/dev/null」再處理「2>&1」。如果聽到這裡你覺得怪的話,再告訴你一件很幹的事。用「2>&1 >/dev/null」並不會將 stderr 導到 /dev/null。「man bash」裡的說明如下:
Note that the order of redirections is significant. For example, the
command
ls > dirlist 2>&1
directs both standard output and standard error to the file dirlist,
while the command
ls 2>&1 > dirlist
directs only the standard output to file dirlist, because the standard
error was duplicated as standard output before the standard output was
redirected to dirlist.




