LoginSignup
0
0

More than 3 years have passed since last update.

xargs コマンドの空白区切り処理

Last updated at Posted at 2019-09-25

こんにちは。
xargs コマンドの空白文字区切り処理(word-splitting by spaces)について ls コマンドで試してみました1
なお -J オプションは POSIX を独自拡張したものです(GNU xargs は持っていません)。-J-n1 を合わせて指定した場合は -I と同じ挙動のようです2

$ ls file_a  file_b
file_a  file_b
$
$ echo file_a  file_b | xargs ls
$ echo file_a  file_b | xargs -L1 ls
$ echo file_a  file_b | xargs -J% ls %
$ echo "file_a  file_b" | xargs ls
$ echo "file_a  file_b" | xargs -L1 ls
$ echo "file_a  file_b" | xargs -J% ls %
file_a  file_b
$
$ echo file_a  file_b | xargs -n1 ls
$ echo file_a  file_b | xargs -n1 -I% ls %
$ echo file_a  file_b | xargs -n1 -J% ls %
$ echo "file_a  file_b" | tr -s ' ' '\n'
$ echo "file_a  file_b" | xargs -n1 ls
$ echo "file_a  file_b" | xargs -n1 -I% ls %
$ echo "file_a  file_b" | xargs -n1 -J% ls %
file_a
file_b
$

  1. xargs コマンドのデフォルトでの「空白文字」区切りは、改行、タブなども含んでいます。 

  2. -J オプションを使わず xargs -J% ls % と同等のことを実現したい場合の方法が現在不明です。 

0
0
0

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