does cd command in a shell script load the rvmrc i

2019-05-16 14:50发布

when you have something like..

given inside projectx an .rvmrc file specifying ruby 1.9.2 and having two rubies on my system (ree-1.8.7 and ruby1.9.2)

#!/bin/bash

cd applications/projectx
which ruby
ruby -v

the last two lines output ree-1.8.7 and its path which was not I intended to use.

标签: ruby shell rvm cd
3条回答
小情绪 Triste *
2楼-- · 2019-05-16 15:23

You need to source rvm inside your script, when you run a script it doesn't load your .bashrc. Simply add a line like

[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm

to the start of your script.

查看更多
我想做一个坏孩纸
3楼-- · 2019-05-16 15:28

Yes


Rvm does define a wrapper around cd that looks like this:

cd () 
{ 
    builtin cd "$@";
    local result=$?;
    __rvm_project_rvmrc;
    __rvm_after_cd;
    return $result
}

It's difficult to tell why your .rvmrc isn't working. Rvm does support project-specific .rvmrc files, but you didn't post yours.

查看更多
手持菜刀,她持情操
4楼-- · 2019-05-16 15:32

If you are using RVM 1.7.0 or later you need to enable project specific .rvmrc files by adding this line to ~/.rvmrc (or system .rvmrc):

rvm_project_rvmrc=1

See: https://rvm.io/workflow/rvmrc/

查看更多
登录 后发表回答