1
0

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.

shell でネストされた変数を展開したい

Posted at

問題

Ruby の bundle install 時に
RAILS_ENV=development なら bundle install --without development
RAILS_ENV=production なら bundle install --without development:test みたいなことをやりたい

例えば

$ config_staging=hoge
$ config_production=fuga
$ target=staging

のとき、 config_${target} の中身の hoge を呼び出したい

解決策

eval を使う

$ echo "$(eval echo \${config_${target}})"
hoge

# or

$ config=\$config_${target}
$ echo $config
$config_staging

$ echo "$(eval echo $config)"
hoge
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?