4

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?

Arek
  • 255

1 Answers1

11
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"
}

or better

if  rm myf ; then
      echo "File is removed successfully" 
      echo "another command executed when rm was successful"
else
      echo "File is not removed" 
      echo "another command executed when rm was NOT successful"
fi
kubanczyk
  • 14,252