|
发表于 2010-10-25 10:46:10
|
显示全部楼层
jacuro正解,shell在管道行中的任何命令执行前,已经把重定向操作符处理完毕,因此在重定向操作符是“>”时且noclobber选项没开时,文件内容被毁,管道行中的任何命令看到的该文件都是空的。
另外,至于管道行中的命令分配std{in,out}和处理重定向的先后顺序,POSIX:2008的XCU中说:The standard input, standard output, or both of a command shall be considered to be assigned by the pipeline before any redirection specified by redirection operators that are part of the command. 因为fork和exec是分离的,因此这里并不是说是在命令执行之后才处理重定向的...吗?吧! |
|