ls
としましょう retunrs file1 file2 dir1 dire2 ...
、you have file1 file2 dir1 dire2 ... in currnent folder
を印刷したい 。
どうすればそれができますか?
ls | xargs -i echo 'you have {} in current folder'
プリント
you have file1 in current folder you have file2 in current folder you have dir1 in current folder you have dir2 in current folder you have xxx in current folder
また、
ls |xargs printf 'you have %s %s %s %s in current folder'
しかし、それを機能させることができませんでした。ファイルの数は不定です。 printf
の正しい構文は何ですか この場合?
ls | xargs printf 'you have [email protected] in current folder'
私が得ることができる最も近いものですが、機能しません。
承認された回答:
以下は機能しますが、おそらくセキュリティにマイナスの影響があります:
echo "You have" * "in current folder"
IMOの方が良い方法ですが、2行が必要になるのは次のとおりです。
files=(*)
echo "You have ${files[@]} in curent folder"
printfを使用する場合:
files=(*)
printf '%s ' "You have ${files[@]} in current folder"