2010-10-21 1037 views

回答

13

從慶典的手冊頁:

-c string If the -c option is present, then commands are read from 
      string. If there are arguments after the string, they are 
      assigned to the positional parameters, starting with $0. 

例子:

$ bash -c ls 

將推出bash和執行命令ls

/bin/sh通常是一個符號鏈接到一個shell。

+1

與沒有'-c'的情況有何不同? – user3155368 2016-04-01 16:35:30

+1

您可以傳遞腳本作爲參數'bash myScript',但它會打開'myScript'並解釋命令。這與'bash -c someCommand'不一樣。比較一下,如果你使用'bash ls'和'bash -c ls',會發生什麼情況。 – aioobe 2016-04-01 18:05:57

+0

/bin/sh -c grep「cpu cores」/ proc/cpuinfo | uniq | sed -e's/[^ 0-9] 上述命令沒有給出預期的結果。爲什麼這樣? 鑑於 /bin/sh -c ls | grep c 工作正常。 我沒有得到這種奇怪的行爲。如果你可以解釋它也會很棒。 – 2017-08-16 13:21:53