「xargs bash -ic echo」が「xargs echo」または「xargs」と異なるのはなぜですか?

「xargs bash -ic echo」が「xargs echo」または「xargs」と異なるのはなぜですか?

ご注文を楽しみにしています

ls -d doc/* | grep -P "<some_pattern>" | xargs bash -ic echo

以下を行います。

ls -d doc/* | grep -P "<some_pattern>" | xargs echo

ls -d doc/* | grep -P "<some_pattern>"つまり、改行ではなくスペースで区切られた一致するファイルを提供します。

しかし、出力として改行文字のみを取得します。

なぜこれですか?必要な操作を実行するように最初のコマンドを変更するにはどうすればよいですか?

zshしかし、実際には代わりに使用していますが、bashどちらも機能しません。

実際、「grep」で指定されたパターンと一致するファイル名を持つ複数のファイルを印刷し、.zshrc-aliasedコマンドを使用して印刷する必要がある場合は、この機能が必要です。

ベストアンサー1

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.

だから...

 $ echo a b c d e f g | xargs bash -ic echo

 $ echo a b c d e f g | xargs bash -ic 'echo $0 $@'
 a b c d e f g

おすすめ記事