Switching rubies in shell script

gcu*_*bed 1 shell jruby rvm

When executing a bash shell script I am using ruby 1.9.3. Then, within the script, I want to switch to JRub (I'm using rvm). I tried switching to JRuby by doing rvm use jruby within the script, but this didn't work, it said:

RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.

./run.sh: line 10: jruby: command not found
Run Code Online (Sandbox Code Playgroud)

当我type rvm | head -n1在命令提示符处执行时,我得到:rvm is a function.所以我不确定这个问题.我以为可能是因为我使用sudo(sudo rvm install jruby)安装了JRuby .所以我使用sudo再次运行shell脚本.我再次收到错误.

如何使用rvm在bash shell脚本中切换rubies?

谢谢

gcu*_*bed 6

我之前把这个添加到了这行:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
Run Code Online (Sandbox Code Playgroud)

正如在这个帖子中所解释的那样(抱歉 - 虽然我之前知道过这个帖子,但我并没有完全掌握它):

RVM不会切换Rubies