soarinblue
soarinblue

Reputation: 1687

what does this shell statement mean?

When I install nvm, I meet this shell statement [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh".

In this statement, [ -s "$NVM_DIR/nvm.sh" ], what does it mean?

Upvotes: 0

Views: 35

Answers (1)

larsks
larsks

Reputation: 312620

In a shell script, the [ command is an alias for the test command, which is used to implement conditional expressions.

If you read the "Conditional Expressions" section of the bash man page, you will find:

   -s file
          True if file exists and has a size greater than zero.

So the expression [ -s "$NVM_DIR/nvm.sh" ] is a conditonal expression that returns success (0) if the file at $NVM_DIR/nvm.sh both exists and has a size greater than 0.

The complete expression...

[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh".

...reads, basically, "if the file exists and has a size greather than 0, source the file into the current shell".

Upvotes: 1

Related Questions