Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > muc.lists.netbsd.tech.userlevel > #11707
| From | Crystal Kolipe <kolipe.c@exoticsilicon.com> |
|---|---|
| Newsgroups | muc.lists.netbsd.tech.userlevel |
| Subject | Re: set -e again |
| Date | 2026-01-14 10:28 +0000 |
| Organization | Newsgate at muc.de e.V. |
| Message-ID | <aWdv1ZpNO4v-29BG@exoticsilicon.com> (permalink) |
| References | <aWbu963HcQMeCm2M@netbsd.org> |
On Wed, Jan 14, 2026 at 01:18:47AM +0000, David Holland wrote:
> I discovered the following today.
>
> This:
> set -e
> f() {
> echo foo
> false
> echo bar
> }
> f
>
> as one might expect, prints "foo" and exits.
>
> However, this:
> set -e
> f() {
> echo foo
> false
> echo bar
> }
> f || echo baz
> echo buzz
>
> prints "foo", "bar", "buzz", and continues. Furthermore, all the
> shells I have in easy reach agree on it.
>
> This seems wrong - the exit status of the f is guarded, but the false
> is not. But also, the fact that everybody agrees makes me think it's
> probably the agreed result of the last round of POSIX wrangling over
> the -e definition some years back.
>
> Is this intended, and is there a way to get the user's intended
> behavior of exit on unchecked failure back? (E.g. is there a different
> set to get functions to return on unchecked failure that might cover
> this?)
Does this achieve what you want?
#!/bin/sh
set -e
f() {
echo foo
false
echo bar
}
f
[ $? ] || echo baz
echo buzz
--
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
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