tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: set -e again



    Date:        Wed, 14 Jan 2026 10:28:37 +0000
    From:        Crystal Kolipe <kolipe.c%exoticsilicon.com@localhost>
    Message-ID:  <aWdv1ZpNO4v-29BG%exoticsilicon.com@localhost>

  | Does this achieve what you want?
  |
  | #!/bin/sh
  | set -e
  | f() {
  | 	echo foo
  | 	false
  | 	echo bar
  | }
  | f
  | [ $? ] || echo baz
  | echo buzz

I doubt it.

[ $? ] is always true.   $? is never '' which is the only way that
could be false.   If it were [ $? -ne 0 ] it would be closer.

But worse than that, the f call is now subject to the -e setting,
which it wasn't before - if the real f() (whatever caused the test
case to be created in the first place - no-one really wants a script
which just outputs foo bar baz buzz in this way - happened to end in
a "return 1" or similar (we must assume that is intended, or the
"|| echo ..." after its call wouldn't be there) is now going to make
the script exit, as f has failed.

Using -e is just not worth the bother, it is a nuisance, always has
been.   But it makes writing simple makefiles simple - it is what
causes the make script to stop as soon as one of the commands in it
fails.

kre




Home | Main Index | Thread Index | Old Index