bash 进程替换 - tr 表示“额外操作数 /dev/fd/63”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14941841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Process substitution - tr says 'extra operand /dev/fd/63'
提问by evsmith
I'm struggling to understand process substitution. As far as I know,
我正在努力理解过程替换。据我所知,
echo abcd | tr -d 'b'
tr -d 'b' <(echo abcd)
should both give the same output. But the first one works (output is 'acd') but the second says
应该都给出相同的输出。但是第一个有效(输出是'acd')但第二个说
tr: extra operand '/dev/fd/63'
Why is this? Doesn't tr just receive 'abcd' through the pipe, and not '/dev/fd/63' as well?
为什么是这样?tr 不只是通过管道接收 'abcd' 而不是 '/dev/fd/63' 吗?
回答by ruakh
The way process substitution works is, Bash will replace <(echo abcd)with (for example) /dev/fd/63, which most common *nix utilities will treat like a filename and open instead of standard input. tr, however, does notaccept a filename argument; it onlytakes standard input.
进程替换的工作方式是,Bash 将替换<(echo abcd)为 (for example) /dev/fd/63,最常见的 *nix 实用程序会将其视为文件名并打开而不是标准输入。tr然而,这并不能接受一个文件名参数; 它不仅需要标准输入。
To pass the result of <(echo abcd)on standard input, you can use another <:
要传递<(echo abcd)标准输入的结果,您可以使用另一个<:
tr -d b < <(echo abcd)

