echoが/bin/sh -c echo fooと呼ばれ、何も出力しないのはなぜですか?

echoが/bin/sh -c echo fooと呼ばれ、何も出力しないのはなぜですか?

たとえば、これが機能している間:

$エコフー
金持ち

以下は行われません。

$/bin/sh -c エコ foo

そしてこれは本当です:

$/bin/sh -c 'エコ foo;エコバー'
金持ち
バー

説明がありますか?

ベストアンサー1

~からman sh

-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

これは、コマンドが次のようになることを意味します。

 $ sh -c 'echo "$0"' foo 
 foo

同様に:

$ sh -c 'echo "$0 $1"' foo bar
foo bar

これは理解すべき最初の部分です。 2番目のケースは簡単で、説明は必要ありません。

おすすめ記事