27
33

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

シェルスクリプトの便利なやつ

Last updated at Posted at 2014-06-06

何時も忘れてググりながらなので備忘録メモ的に

##引数の数だけループ処理を行う


for x in "$@"
do

  echo "$x"

done

これをやると引数の数だけループしてくれます
"$@"と囲むことで各引数にスペースが含まれていても正しく処理されます


d104:~ nagane$ cat test.sh
#!/bin/bash
for x in "$@"
do
  echo "$x"
done

d104:~ nagane$ sh test.sh sushi yuki 'ho shi'
sushi
yuki
ho shi
d104:~ nagane$

shiftを使ってループを回す方法もありますが
そんな複雑な事しなくても良いならこっちの方が綺麗に書けます。

27
33
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
27
33

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?