How do I set the shell to bash for run in Capistrano?

限于喜欢 提交于 2020-01-22 13:31:31

问题


How can I set the shell in the Capistrano run command to use bash instead of sh? I am trying to install RVM and I need to execute the command:

run "bash < <(curl -L http://bit.ly/rvm-install-system-wide)"

as in:

task :install_rvm, :roles => :server do
  apps = %w(bison openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev     libyaml-dev sqlite3 libsqlite3-0 libxml2-dev libxslt-dev autoconf subversion libcurl4-openssl-dev)
  apt.install( {:base => apps}, :stable )
  run "bash < <(curl -L http://bit.ly/rvm-install-system-wide)"
  run "rvm install 1.9.2".sh
  run "rvm use 1.9.2@global"
  run "gem install awesome_print map_by_method wirble bundler builder pg cheat"
  run "gem install -v2.1.2 builder"
  # modify .bashrc
end

But I just can't seem to get it to work because Capistrano is executing:

"sh -c 'bash < <(curl -L http://bit.ly/rvm-install-system-wide)'" on ubuntu@ec2...

I see in the Capistrano gem the command.rb file has some code like

shell = "#{options[:shell] || "sh"} -c"

but it is unclear to me how to pass options[:shell] to the task


回答1:


set :shell is not working, but that works:

default_run_options[:shell] = '/bin/bash'




回答2:


It sounds like you need the rvm-capistrano gem. Another option would be to use the mechanism used by rvm-capistrano, that is:

set :default_shell, '/bin/bash -l'



回答3:


Try setting the :shell variable.

set :shell, '/usr/bin/bash'



回答4:


You can also use the following syntax:

run "bash -c <command>"

It is especially useful for setting environment with --login switch, for example:

run "bash --login -c rvm use 1.9.2

...and it also works in Capistrano 3.x...!



来源:https://stackoverflow.com/questions/7747759/how-do-i-set-the-shell-to-bash-for-run-in-capistrano

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!