如何将 shell 设置为 bash 以在 Capistrano 中运行?
如何在 Capistrano run 命令中将 shell 设置为使用 bash 而不是 sh? 我正在尝试安装 RVM 并且需要执行命令:
run "bash < <(curl -L http://bit.ly/rvm-install-system-wide)"
如下所示:
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
但我似乎无法让它工作,因为 Capistrano 正在执行:
"sh -c 'bash < <(curl -L http://bit.ly/rvm-install-system-wide)'" on ubuntu@ec2...
我在 Capistrano gem 中看到 command.rb 文件有一些代码,例如
shell = "#{options[:shell] || "sh"} -c"
但是我不清楚如何将 options[:shell]
传递给任务
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
set :shell 不起作用,但可以:
default_run_options[:shell] = '/bin/bash'
set :shell is not working, but that works:
default_run_options[:shell] = '/bin/bash'
听起来您需要 rvm-capistrano gem。另一种选择是使用 rvm-capistrano 使用的机制,即:
It sounds like you need the rvm-capistrano gem. Another option would be to use the mechanism used by rvm-capistrano, that is:
尝试设置
:shell
变量。Try setting the
:shell
variable.您还可以使用以下语法:
它对于使用 --login 开关设置环境特别有用,例如:
...并且它也适用于 Capistrano 3.x...!
请务必将命令用单引号括起来,以便将其作为单个参数传递给 bash,这样就不会过早执行路径名扩展(通配符)、参数扩展等。
You can also use the following syntax:
It is especially useful for setting environment with --login switch, for example:
...and it also works in Capistrano 3.x...!
Be sure to wrap the command in single quotes so that it is passed to
bash
as a single argument, and so that pathname expansion (globbing), parameter expansion and so on are not performed too early.