LoginSignup
0
0

More than 3 years have passed since last update.

コマンドの出力値を取得(xargs で受け取った中で)

Last updated at Posted at 2021-01-13

こんにちは。
コマンドの出力値を($(command))、xargs で受け取った中で取得しました。コメントをいただき、正しく動くように修正しました。今回例では basename コマンドの出力値を確認しています。

$ find . -name "*.txt" | xargs -I% sh -c 'echo "$(basename "%" .txt)"'
a
b
$ ls .
a.txt  b.txt

while read ループ利用

while read ループ利用でも試しました。

$ find . -name "*.txt" | while read f; do echo "$(basename "$f" .txt)"; done
a
b
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0