bug-bash
[Top][All Lists]
Advanced

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

Re: why "shopt -p" sometime return non-zero ?


From: Martin D Kealey
Subject: Re: why "shopt -p" sometime return non-zero ?
Date: Thu, 25 Sep 2025 11:41:48 +1000

On Wed, Sep 24, 2025 at 22:55+1000, Jean-Jacques Brucker wrote:

> So "... || true" is here required when "set -e".


On Thu, 25 Sept 2025 at 09:03+1000, Duncan Roe via Bug reports for the GNU
Bourne Again SHell <bug-bash@gnu.org> wrote:

> `||:` also works - I use it sometimes in SBo scripts (all their templates
> have
> `set -e`).
>

Or a leading ‘!’, like:

! saved_shopts=$( shopt -p )

Aside from a stylistic preference for a suffix rather than prefix, I wonder
why this isn't more commonly suggested?

-Martin

PS: a prefix ‘!’ does *not* cause errexit to be triggered when the command
has a zero exit status, and it's been that way for a long time:
$ set -e ; ! true ; ! false ; type ! ; echo $BASH_VERSION ; false ; echo
Still here
! is a shell keyword
2.01.0(1)-release


reply via email to

[Prev in Thread] Current Thread [Next in Thread]