Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think you answered your own question. Those `if` constructs are indeed clunky. In fact I'd venture to say it's really just "C-like language Stockholm syndrome" that makes them feel more "maintainable" or "clear".

The bash "or" syntax reads very clearly. Do X or do Y. Do X or fail like so. It's very English-like and intuitive. And understanding why it works is just a matter of understanding logical operator short circuiting, which you have to understand to work in C-like languages anyway.



Problem is you have to fork subshells if here is any sequencing involved. Compare

  if condition ; then
    command1
    command2
  else
    command3
    command4
  fi
versus:

  condition && (command1; command2) || (command3; command4)
GNU Bash has a fix for that: non-forking braces.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: