- 论坛徽章:
- 1
|
十三问中有这么一段:
"cat < file > file 之后原本有内容的档案结果却被洗掉了﹗
要理解这一现像其实不难,这只是 priority 的问题而已:
* 在 IO Redirection 中, stdout 与 stderr 的管道会先准备好, 才会从 stdin 读进资料。
也就是说,在上例中,> file 会先将 file 清空,然后才读进 < file , 但这时候档案已
经被清空了,因此就变成读不进任何数据了... "
上面这个按照优先级解释可以说通,但是 "cat <> file" 按照优先级来理解就不大明白了,同样也是stdout和stderr会先准备好,
那file也应该被清空呀,实际上file并没有被清空,ls -lrt 查看file,时间戳也没有更新
另外BASH中说的输入输出是从左至右,也并没有说到优先级问题:
REDIRECTION
Before a command is executed, its input and output may be redirected using a special notation
interpreted by the shell. Redirection may also be used to open and close files for the current
shell execution environment. The following redirection operators may precede or appear anywhere
within a simple command or may follow a command. Redirections are processed in the order they
appear, from left to right.
cat < file > file
cat <> file
区别到底在哪里哇,要撞墙壁了,表示非常迷惑,求指点
|
|