Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain this command: . ~/nvm/nvm.sh

Tags:

linux

bash

nvm

I am by no means a novice user on Linux, but I just don't understand why one has to put . in front of this command:

. ~/nvm/nvm.sh

For those in the know, this is how to activate the nvm bash script (it allows for a virtual environment in the NodeJS universe). But if one does not put that starting period in front of the command, then things don't work out. As far as I know, the "." means current directory. Yet if I do this:

cd ~/nvm
nvm.sh

or this

~/nvm/nvm.sh

It will not work. Why? Why must one put "." and then a space before running this command.

like image 589
Barry Steyn Avatar asked Dec 06 '22 12:12

Barry Steyn


1 Answers

. ~/nvm/nvm.sh

It asks the interpreter to interpret the script in the current process. In bash it's equivalent to:

source ~/nvm/nvm.sh

You need to execute a script in the current process if you want it to change the environment (variables, et al). You can view more details with help .


~/nvm/nvm.sh

This one actually runs the script in a new bash process. It cannot change the environment of the parent, for example it cannot export variables to the parent process.

like image 174
cnicutar Avatar answered Dec 20 '22 14:12

cnicutar