LoginSignup
6
4

More than 5 years have passed since last update.

bashで引数を配列処理する

Last updated at Posted at 2016-11-23

最近bashで引数を持たせるときに
\$1,$2を使って変数に引数を入れるのがめんどくさいのとコードが煩雑になるので、
配列が使えないかと思って調べたらdeclareコマンドで変数宣言ができることを知りました。

実際にbashで引数の値を配列を入れるときは以下のようにしています。

Array.sh
declare -a array
for a in $@;do
    array=("${array[@]}" $a)
done

皆さんもぜひ使ってみてください。

6
4
1

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
4