Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > muc.lists.netbsd.tech.userlevel > #11712
| From | Robert Elz <kre@munnari.OZ.AU> |
|---|---|
| Newsgroups | muc.lists.netbsd.tech.userlevel |
| Subject | Re: set -e again |
| Date | 2026-01-14 21:22 +0700 |
| Organization | Newsgate at muc.de e.V. |
| Message-ID | <5133.1768400569@jacaranda.noi.kre.to> (permalink) |
| References | <> <aWdv1ZpNO4v-29BG@exoticsilicon.com> |
Date: Wed, 14 Jan 2026 10:28:37 +0000
From: Crystal Kolipe <kolipe.c@exoticsilicon.com>
Message-ID: <aWdv1ZpNO4v-29BG@exoticsilicon.com>
| 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
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Back to muc.lists.netbsd.tech.userlevel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
set -e again David Holland <dholland-tech@netbsd.org> - 2026-01-14 01:18 +0000
Re: set -e again "Greg A. Woods" <woods@planix.ca> - 2026-01-13 18:14 -0800
Re: set -e again Mouse <mouse@Rodents-Montreal.ORG> - 2026-01-13 21:30 -0500
Re: set -e again Crystal Kolipe <kolipe.c@exoticsilicon.com> - 2026-01-14 10:28 +0000
Re: set -e again Mouse <mouse@Rodents-Montreal.ORG> - 2026-01-14 07:41 -0500
Re: set -e again Crystal Kolipe <kolipe.c@exoticsilicon.com> - 2026-01-14 13:46 +0000
Re: set -e again Robert Elz <kre@munnari.OZ.AU> - 2026-01-14 21:22 +0700
Re: set -e again RVP <rvp@SDF.ORG> - 2026-01-14 13:39 +0000
Re: set -e again Robert Elz <kre@munnari.OZ.AU> - 2026-01-14 21:09 +0700
csiph-web