2017-06-04 27 views
-2

的優點是沒有任何實際的好處是用bash -c 'some command'在使用bash <<< 'some command'什麼是使用bash -c在使用此字符串

他們似乎達到同樣的效果。

+0

的好處是不必重定向與'bash的-c'一切... –

+0

你這是什麼意思呢? – yosefrow

+0

'<<<'(這裏是字符串)和重定向,這就是我的意思。 –

回答

6
  • 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' 
/