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

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

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

before ~/.bash_profile .

What does this line do?

thanks

+6
source share
3 answers

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

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

&&

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

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

. not suitable for source command. You upload the file to your current shell and do not open a new sub-shell

+12
source

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

The file "$HOME/.rvm/scripts/rvm . $ HOME is a variable usually installed in your homedir ( ~ ), something like /home/youruser . In this directory you will find a hidden .rvm folder that contains scripts for folders which contains an executable file named rvm .

+1
source

I just installed rvm and ran rvm notes as a shell command. The output includes the following lines in addition to useful information.

  • If you want to use RVM interactively in other shells then put the following line at the end of the shell boot 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 think it’s always useful to take a look at the latest release notes.

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

+1
source

Source: https://habr.com/ru/post/906800/


All Articles