什么是使用bash -c在使用此字符串
问题描述:
的优点是没有任何实际的好处是用bash -c 'some command'
在使用bash <<< 'some command'
什么是使用bash -c在使用此字符串
他们似乎达到同样的效果。
答
bash -c '...'
留下您的选择提供标准输入输入命令,而
bash <<<'...'
排除了选择,因为标准输入已被使用,以提供脚本来执行。
例子:
# Executes the `ls` command then processes stdin input via `cat`
echo hi | bash -c 'ls -d /; cat -n'
/
1 hi
# The here-string input takes precedence and pipeline input is ignored.
# The `ls` command executes as expected, but `cat` has nothing to read,
# since all stdin input (from the here-string) has already been consumed.
echo hi | bash <<<'ls -d /; cat -n'
/
的好处是不必重定向与'bash的-c'一切... –
你这是什么意思呢? – yosefrow
'