Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > muc.lists.netbsd.tech.userlevel > #11704

set -e again

From David Holland <dholland-tech@netbsd.org>
Newsgroups muc.lists.netbsd.tech.userlevel
Subject set -e again
Date 2026-01-14 01:18 +0000
Organization Newsgate at muc.de e.V.
Message-ID <aWbu963HcQMeCm2M@netbsd.org> (permalink)

Show all headers | View raw


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?)

-- 
David A. Holland
dholland@netbsd.org

--
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 | NextNext in thread | Find similar


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