【发布时间】:2016-06-07 07:44:39
【问题描述】:
在 bash 1 中:
$ mkfifo /tmp/pipe
$ echo 'something' > /tmp/pipe
现在它挂起并等待读取数据。
在 bash 2 中:
$ </tmp/pipe
现在 shell 1 消失了,它关闭了,我的终端消失了。
为什么会这样?
在bash手册中有写
命令替换 $(cat file) 可以替换为 等效但更快 $(
所以我正在试验普通的“
$ bash --version | head -1
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
$ cat /proc/version
Linux version 3.16.0-71-generic (buildd@lgw01-46) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #92~14.04.1-Ubuntu SMP Thu May 12 23:31:46 UTC 2016
编辑
在看到最初的 cmets 和答案后,我将添加一些说明。
我不关心不同的命令行语法。
但我真正想要的是在阅读器外壳$ < /tmp/pipe 场景中编写器外壳退出,但在阅读器外壳中使用$ cat /tmp/pipe 时,编写器外壳不会退出。为什么?
我发现我真的没有在问题和正文中表达这个问题,应该可能会提出另一个问题?
【问题讨论】:
-
$(< file)是命令替换的特例;< file不是cat file的通用替代品。
标签: bash named-pipes