Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does [[ -s mean in linux shell

Tags:

linux

shell

I found this command. I understand the source reloads the bash profile and fixed permissions for Ruby permissions needed on Ubuntu. But what does the part before && mean?

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

1 Answers

Let's break it down:

the [[ and ]] enables advanced functionality that is more similar to traditional programming languages, allowing constructs like || instead of -o and && instead of -a.

For more information on this see How to use double or single brackets, parentheses, curly braces but as far as I know -s does not need the extra functionality and the double brackets could be replaced with single brackets)

the -s tests whether the file exists and is non-empty

&& will automatically run the command on the right, as long as the command on the left executes without an error return code.

So, the statement tests whether the file exists and is non-empty, and if so it will source it into the current shell environment.

like image 53
DavidDraughn Avatar answered Nov 04 '25 06:11

DavidDraughn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!