Logical chaining of commands with && and ||

suggest change

&& chains two commands. The second runs only if the first exits with success. || chains two commands, but the second runs only if the first exits with failure.

[ a = b  ] && echo "yes" || echo "no"

# if you want to run more commands within a logical chain, use curly braces
# which designate a block of commands 
# They do need a ; before the closing brace so Bash can differentiate it from other uses
# of curly braces
[ a = b ] && { echo "let me see." 
               echo "hmmm, yes, i think it is true" ; } \
          || { echo "as i am in the negation i think " 
               echo "this is false. a is a not b."  ; }
# mind the use of line continuation sign \
# only needed to chain yes block with || ....

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents