LoginSignup
6

More than 5 years have passed since last update.

$1,$2,$3...に値をセットする方法

Last updated at Posted at 2015-10-29

これが出来て嬉しいケースってのがよく分からんがそういう機能があるようなのでメモ。

$ # $@が空なのを確認
$ echo "[$*]" "${#@}"
[] 0

$ # $1,$2,$3 に値をセット
$ set -- one two three
$ # $@の内容を確認
$ echo "[$1,$2,$3]" "${#@}"
[one,two,three] 3

$ # 既に $1,$2,$3に値が入ってる状態からより少ない数の値をセットすると…
$ set -- one two
$ # 元々あった余分な $3 は unset される
$ echo "[$1,$2,$3]" "${#@}"
[one,two,] 2

これだけ。

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
6