Skip to main content
1 of 2
Hauke Laging
  • 94.6k
  • 21
  • 132
  • 185
if true; then
  echo true
  test -e doesntexist
else
  echo false
fi

can be rewritten with && and || by making sure the exit code of the code blocks. Instead of

true && { echo true; test -e doesntexist; } || echo false

you need

true && { echo true; test -e doesntexist; true; } || echo false

elif

if test -e exists; then
  echo true
elif test -e doesntexist
  echo elif
else
  echo false
fi

would be

test -e exists && { echo true; true; } ||
  { test -e doesntexist && { echo elif; true; } || echo false; }
    
Hauke Laging
  • 94.6k
  • 21
  • 132
  • 185