2010-10-21 7 views

risposta

13

Dalla pagina man di bash:

-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. 

Esempio:

$ bash -c ls 

lancerà bash ed eseguire il comando ls.

/bin/sh è in genere un collegamento simbolico a una shell.

+1

In che modo è diverso senza '-c'? – user3155368

+1

È possibile passare uno script come argomento, 'bash myScript', ma aprirà' myScript' e interpreterà i comandi. Questo non è lo stesso di 'bash -c someCommand'. Confronta cosa succede se esegui 'bash ls' e' bash -c ls' per esempio. – aioobe

+0

/bin/sh -c grep "cpu core"/proc/cpuinfo | uniq | sed -e 's/[^ 0-9] Il comando precedente non dà il risultato desiderato. Perché è così? Mentre /bin/sh -c ls | grep c funziona bene. Non ho questo strano comportamento. Sarebbe bello se lo spiegassi anche tu. –