Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm": What does it do?

Tags:

bash

I am installing Ruby on Rails on Mac OS X. The tutorial I am following says to add:

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

to ~/.bash_profile.

What does this line do?

Thanks

like image 818
Tyler DeWitt Avatar asked Jan 24 '12 22:01

Tyler DeWitt


3 Answers

[[ -s "$HOME/.rvm/scripts/rvm" ]]

This portion is a test condition ([[ is the new test command). -s returns TRUE if the file rvm present over at $HOME/.rvm/scripts/ location exists and is of size greater than zero.

&&

This is a logical and operator. It executes the statement on the right IF AND ONLY IF statement on the left returns true.

. "$HOME/.rvm/scripts/rvm"

. is short for source command. You are sourcing the file in your current shell and not forking a new sub-shell

like image 152
jaypal singh Avatar answered Nov 15 '22 06:11

jaypal singh


It checks if the file exists and has size great than zero, and if so, it executes the file.

The file is "$HOME/.rvm/scripts/rvm. $HOME is a variable, usually set to your homedir (~), something like /home/youruser. In that directory you should find a hidden folder .rvm, which contains a folder scripts, which contains an executable file called rvm.

like image 29
Konerak Avatar answered Nov 15 '22 05:11

Konerak


I just installed rvm and run rvm notes as a shell command. The output includes besides other useful information the following lines.

  • If you wish to use RVM in an interactive fashion in other shells then place the following line at the end of your shell's loading files (.bashrc or .bash_profile for bash and .zshenv for zsh), after all PATH/variable settings:

    [[ -s "/home/username/.rvm/scripts/rvm" ]] && source "/home/username/.rvm/scripts/rvm" # This loads RVM into a shell session.

I guess it is always a good idea to take a look at the latest release notes.

Also I found the "How to use RVM" screencast very helpful! It also includes information about your question in the first minutes.

like image 26
JJD Avatar answered Nov 15 '22 07:11

JJD