Conditional blocks of code in linux bash

Posted by Arek on Server Fault See other posts from Server Fault or by Arek
Published on 2010-12-27T15:15:57Z Indexed on 2010/12/27 15:55 UTC
Read the original article Hit count: 288

Filed under:
|

Nearly everybody knows very useful && and || operators, for example:

rm myf && echo "File is removed successfully" || echo "File is not removed"

I've got a question: how to put a block of commands after && or || operators without using the function?

For example I want to do:

rm myf && \
  echo "File is removed successfully" \
  echo "another command executed when rm was successful" || \
  echo "File is not removed" \
  echo "another command executed when rm was NOT successful"

What is the proper syntax of that script?

© Server Fault or respective owner

Related posts about bash

Related posts about conditional