Order matters. The way to reason about redirections is to read them from left to right and realize that redirections make streams point at the same place. They don’t make streams point at each other.
What does that mean? If you say 2>&1 then you are redirecting stderr to wherever stdout is currently redirected to. If stdout is going to the console then stderr is, too. If stdout is going to a file then stderr is as well. If you follow this up by then redirecting stdout, stderr still points to what stdout used to point to. It does not “follow” stdout to the new location.
那是什么意思?如果你这么说,2>&1那么你正在将stderr重定向到stdout当前被重定向到的任何地方。如果标准输出到控制台,那么stderr也是。如果标准输出到一个文件,那么stderr也是。如果您通过重定向标准输出继续执行此操作,stderr仍会指向stdout 用于指向的内容。它不会“跟随”stdout到新的位置。
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/94068
评论列表(1条)
补充: cmd 2>&1 >log 错误重定向通过正确重定向直接输出至终端,正确重定向直接输出至log文件
可以通过 (cmd 2>&1) >log 将错误重定向和正确重定向的内容全部输出至文件