And (&&) Or (||) Operators



# In your terminal
echo "hi." || echo "This won't happen."

# Output
hi.


$(ls non_existent_file) || echo "This happens if the first thing fails"

# Output
ls: cannot access non_existent_file: No such file or directory
This happens if the first thing fails


$(ls non_existent_file) && echo "This also happens"

# Output
# 2nd one not executed after the 1st one returns FALSE
ls: cannot access non_existent_file: No such file or directory

Index