railsタスクを変数に格納して実行したい
事象
railsタスクの実行コマンドを変数に入れて実行したいが、予期しないエラーが発生する。
RAILS_TASK='rbenv exec bundle exec rails hogehoge:hoge1[param1,1,2]' $RAILS_TASK # => ./test.sh: line 5: [: too many arguments 解決
“(ダブルクオテーション)に変更
RAILS_TASK="rbenv exec bundle exec rails hogehoge:hoge1[param1,1,2]"
tips
シングルクォーテーション「’」
ワイルドカード文字「*[]」, 不等号、パイプ「 」、スペースが含まれていても文字列の一部です。
This post is licensed under CC BY 4.0 by the author.