Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

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

$ # $@が空なのを確認
$ 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

これだけ。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away