3

I've tried looking everywhere to determine what this line does in my .bashrc. The reason I want to know is because now ~/.pam_environment is recommended. This is the line:

[[ -s /home/$USER/.nvm/nvm.sh ]] && . /home/$USER/.nvm/nvm.sh

I think I've narrowed it to the condition checks to make sure the nvm.sh file exists and that it is larger than 0 bytes. But I don't understand what follows. && normally means "and" but I don't understand why that would be necessary after a check and also why the . is not attached to the filename.

Basically what I want to know is, how would I put this in my .pam_environment file which only takes assigment expressions.

Edit: This line currently allows me to run NVM from the terminal but I'd really like to know just for the sake of learning.

0

1 Answer 1

3

Yes, you are correct that [[ -s ... ] checks whether a file exists. If it does, it will exit with the status 0, and if it doesn't, it will exit as 1 (i.e. fail).

The && command/operator/whatever runs the next command if the command before it succeeded (i.e. the exit status is 0). ||, on the contrary, runs the next command if the command before failed (i.e. not 0).

Having . before the filename (with whitespace in-between) runs the file, but also keeps any environmental variable changes it does. For example, if I make test.sh as this:

#!/bin/bash
FOO=bar
BAR=baz
BAZ=foo
PATH="FOO:$PATH"

and I run . path/to/test.sh, there will be new variables: FOO, BAR, and BAZ, and PATH will be updated. Notice that source, I think, does the same as .. EDIT: Yes, source and . are synonyms in bash.

2
  • So would this be possible to put in the .pam_environment file since variable are being set for the session?
    – Adam Beck
    Jun 20, 2013 at 23:33
  • @AdamBeck I doubt it. Apparently the syntax is very limited (help.ubuntu.com/community/…). I'd recommend going through nvm.sh and copying the variable assignments to .pam_environment.
    – MiJyn
    Jun 21, 2013 at 0:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .