home wiki.fukuchiharuki.me
Menu
*キーワード [#i0701e8b]
-set
-shift

*概要 [#y0057c93]
スペース区切りの文字列を分割します。

*方法 [#h137563c]
-sample.sh
 set `echo i1 i2 i3`
 while [ $# -ne 0 ]
 do
     echo $1
     shift
 done

次の実行結果を得ます。
 $ ./sample.sh
 i1
 i2
 i3
 $

*解説 [#ac13af9a]
$1 や shift は引数を扱うためのものですが set を使うことで引数の代わりにすることができます。

*参考 [#b0696fa9]
-[[bourne shellのTips - web-cahier.com>http://www.web-cahier.com/log/2012/01/bourne-shelltips.html]]