Условные блоки кода в linux bash

Почти все знают, очень полезно && и || операторы, например:

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

У меня вопрос: как поставить блок команд после && или || операторы без использования функции?

Например я хочу сделать:

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"

Каков правильный синтаксис этого скрипта?

1 ответ

Решение
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"
}

или лучше

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
Другие вопросы по тегам