双重定向测试
这会打印你的外壳什么?
echo foo | while read line; do echo $line; done < <(echo bar)
我希望它的计算结果为 echo foo | bar 或 foo < <(bar)
,这两者都会导致错误消息。
在 Bash 4.1.5 中,管道似乎被简单地丢弃了:
bar
在 Dash 中:
sh: Syntax error: redirection unexpected
What does this print your shell?
echo foo | while read line; do echo $line; done < <(echo bar)
I would expect it to evaluate to echo foo | bar
or foo < <(bar)
, both of which would result in an error message.
In Bash 4.1.5 it looks like the pipe is simply discarded:
bar
In Dash:
sh: Syntax error: redirection unexpected
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Dash 不支持进程替换 (
<()
)。如果您使用所比较的每个 shell 支持的语法,您看到的行为是一致的。试试这个:
您应该看到“inputfile”的内容而不是“hello”。在我尝试过的几个 shell 中,只有 Z shell 显示了这两种情况。
这是 POSIX 关于管道和重定向的说法:
我将此解释为,在上面的示例中,管道将 stdin 分配给
cat
,然后重定向会覆盖它。Dash doesn't support process substitution (
<()
).The behavior you're seeing is consistent if you use syntax that's supported by each of the shells you're comparing. Try this:
You should see the contents of "inputfile" and not "hello". Of several shells I tried, only Z shell showed both.
This is what POSIX says regarding pipelines and redirection:
I interpret this to mean that in the case of the example above, the pipeline assigns stdin to
cat
then the redirection overrides it.