如何将 shell 设置为 bash 以在 Capistrano 中运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7747759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I set the shell to bash for run in Capistrano?
提问by Charles
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:
如何在 Capistrano 运行命令中设置 shell 以使用 bash 而不是 sh?我正在尝试安装 RVM,我需要执行以下命令:
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:
但我似乎无法让它工作,因为 Capistrano 正在执行:
"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
我在 Capistrano gem 中看到 command.rb 文件有一些代码,比如
shell = "#{options[:shell] || "sh"} -c"
but it is unclear to me how to pass options[:shell]to the task
但我不清楚如何传递options[:shell]给任务
回答by hipertracker
set :shell is not working, but that works:
set :shell 不工作,但有效:
default_run_options[:shell] = '/bin/bash'
default_run_options[:shell] = '/bin/bash'
回答by adamlamar
It sounds like you need the rvm-capistranogem. Another option would be to use the mechanism used by rvm-capistrano, that is:
听起来您需要rvm-capistranogem。另一种选择是使用 rvm-capistrano 使用的机制,即:
set :default_shell, '/bin/bash -l'
回答by Jonathan Julian
Try setting the :shellvariable.
尝试设置:shell变量。
set :shell, '/usr/bin/bash'
回答by krzy-wa
You can also use the following syntax:
您还可以使用以下语法:
run "bash -c <command>"
It is especially useful for setting environment with --login switch, for example:
它对于使用 --login 开关设置环境特别有用,例如:
run "bash --login -c rvm use 1.9.2
...and it also works in Capistrano 3.x...!
...它也适用于 Capistrano 3.x ...!

