logical chaining of commands with and

suggest change

&& chains two commands. The second one runs only if the first one exits with success. || chains two commands. But second one runs only if first one 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 closing bracket so bash can diffentiate 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:

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

Table Of Contents