sh -c和过程替换 [英] sh -c and process substitution

查看:78
本文介绍了sh -c和过程替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在终端(重击)中,以下工作正常:

In terminal (bash) the following works fine:

cat <(echo "hello") 

但如果我这样做:

sh -c 'cat <(echo "hello")'

我知道

sh: 1: Syntax error: "(" unexpected

您能解释一下原因吗?

顺便说一句,我的总体目标是在shell脚本中编写以下命令:

Btw, my overall aim is to write this command in a shell script:

watch -n 1 'cat <(iptables -L INPUT) <(iptables -L FORWARD)'

但是它不起作用,原因似乎是上述问题.

but it won't work, the reason seems to be the above problem.

推荐答案

sh通常是dash而不是bash(请参见man sh). dash不执行进程替换,仅执行POSIX.

sh is often dash not bash (see man sh). dash doesn't do process substitution, only POSIX stuff.

您需要这样做:

  bash -c 'cat <(echo "hello")'

ksh& zsh也可以进行进程替换.

ksh & zsh can do process substitution too.

通过您的示例,您可以简单地做到:

With your example, you can simply do:

watch -n 1  'iptables -L INPUT;  iptables -L FORWARD'

不需要高级Shell或进程替换.

no need for an advanced shell or process subtitution.

这篇关于sh -c和过程替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆