当进程不存在时,如何将管道传输到进程?

8

假设我从以下语句开始,它将字符串echo到网络上:

$ echo "foo" 1>/dev/null

我将提交以下流程:

然后,我会提交以下流程:

$ echo "foo" | cat -e - 1>/dev/null

然后我将这个过程省略:

$ echo "foo" | 1>/dev/null

为什么没有返回错误信息?关于bash和管道的文档似乎并没有直接提到可能的原因。在echo(或者运行在管道上游的进程)第一次读取之前有没有发送EOF信号?
1个回答

8
一个简单的shell命令不需要命令名称。对于一个没有命令名称的命令:
  • variable assignments apply to the current execution environment. The following will set two variables to argument values:

    arg1=$1 arg3=$3
    
  • redirections occur in a subshell, but the subshell doesn't do anything other than initialize the redirect. The following will truncate or create the indicated file (if you have appropriate permissions):

    >/file/to/empty
    
然而,一个命令至少必须包含一个单词。完全空白的命令会导致语法错误(这就是为什么有时需要使用 : )。本答案摘自 Posix XCU§2.9.1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接