如何将 shell 设置为 bash 以在 Capistrano 中运行?

发布于 2024-12-09 23:45:41 字数 1079 浏览 1 评论 0原文

如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

三人与歌 2024-12-16 23:45:41

set :shell 不起作用,但可以:

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

set :shell is not working, but that works:

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

对你的占有欲 2024-12-16 23:45:41

听起来您需要 rvm-capistrano gem。另一种选择是使用 rvm-capistrano 使用的机制,即:

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

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'
悲歌长辞 2024-12-16 23:45:41

尝试设置 :shell 变量。

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

Try setting the :shell variable.

set :shell, '/usr/bin/bash'
痞味浪人 2024-12-16 23:45:41

您还可以使用以下语法:

execute "bash -c '<command>'"

它对于使用 --login 开关设置环境特别有用,例如:

execute "bash --login -c 'rvm use 1.9.2'"

...并且它也适用于 Capistrano 3.x...!

请务必将命令用单引号括起来,以便将其作为单个参数传递给 bash,这样就不会过早执行路径名扩展(通配符)、参数扩展等。

You can also use the following syntax:

execute "bash -c '<command>'"

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

execute "bash --login -c 'rvm use 1.9.2'"

...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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文