zsh-workers
 help / color / mirror / code / Atom feed
From: "Lawrence Velázquez" <larryv@zsh.org>
To: "Bart Schaefer" <schaefer@brasslantern.com>,
	"Philippe Altherr" <philippe.altherr@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: Inconsistent behavior of ERR_EXIT with conditionals
Date: Tue, 08 Nov 2022 03:04:12 -0500	[thread overview]
Message-ID: <1edb7786-f0b2-4830-88fa-99a19bda39e2@app.fastmail.com> (raw)
In-Reply-To: <CAH+w=7YCNXmVU8Os29tSr1JrnFpGw47EqRfiJKdXNp0P-3KPGw@mail.gmail.com>

On Tue, Nov 8, 2022, at 12:36 AM, Bart Schaefer wrote:
> So you can see that zsh agrees with bash on your "Failure" cases.  The
> output of dash (as /bin/sh on ubuntu) is the same as zsh with the
> exception of Failure-b, which can't be tested because there is no
> equivalent of "declare" (or "local").

Here is a set of tests incorporating most of Philippe's examples
(some slightly modified).  In the output, "no" and "yes" are intended
to indicate whether the shell exited due to "set -e" / ERR_EXIT.
The tl;dr is that zsh agrees with other shells, except on three
constructs from Philippe's original email.

The shells I tested are zsh 5.9, bash 5.1.16(1)-release, ksh AJM
93u+ 2012-08-01, dash 0.5.11.5, and yash 2.52.  For more fun, see
<https://www.in-ulm.de/~mascheck/various/set-e/>.

	% head -n 100 *.sh(n) driver.zsh
	==> 1.sh <==
	f() {
	    { false && true; }
	}
	f
	printf '    no'

	==> 2.sh <==
	f() {
	    false && true
	}
	f
	printf '    no'

	==> 3.sh <==
	f() {
	    if true; then
	        false && true
	    fi
	}
	f
	printf '    no'

	==> 4.sh <==
	f() {
	    case foo in
	        *) false && true ;;
	    esac
	}
	f
	printf '    no'

	==> 5.sh <==
	f() {
	    (false && true)
	}
	f
	printf '    no'

	==> 6.sh <==
	: $(false)
	printf '    no'

	==> 7.sh <==
	if [ "$KSH_VERSION" ]; then
	    f() { typeset v=$(false); }
	else
	    f() { local v=$(false); }
	fi
	f
	printf '    no'

	==> 8.sh <==
	if
	    false
	    printf '    no'
	    true
	then
	    true
	fi

	==> 9.sh <==
	{
	    false
	    printf '    no'
	    true
	} && true

	==> 10.sh <==
	false && true
	printf '    no'

	==> 11.sh <==
	! true
	printf '    no'

	==> driver.zsh <==
	set -- *.sh(n)

	printf '     '
	printf ' %5s' $@
	echo

	for sh in zsh bash ksh dash yash; do
	    printf %4s: $sh
	    for arg; do
	        $sh -e $arg || printf '   yes'
	    done
	    echo
	done
	% zsh driver.zsh
	       1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  7.sh  8.sh  9.sh 10.sh 11.sh
	 zsh:    no   yes    no    no   yes    no    no    no    no    no    no
	bash:   yes   yes   yes   yes   yes    no    no    no    no    no    no
	 ksh:   yes   yes   yes   yes   yes    no    no    no    no    no    no
	dash:   yes   yes   yes   yes   yes    no    no    no    no    no    no
	yash:   yes   yes   yes   yes   yes    no    no    no    no    no    no


> Bash disagrees with dash and
> zsh on your "Success" cases, at least at that version.

Bash disables "set -e" in command substitutions and has done so
since at least 1.14 (the oldest version I can test).  Bash 4.4 added
an option that causes command substitutions to inherit "set -e",
but it remains disabled by default (except in POSIX mode).


-- 
vq


  reply	other threads:[~2022-11-08  8:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-04 16:37 Philippe Altherr
2022-11-06 20:45 ` Bart Schaefer
2022-11-07  3:50   ` Bart Schaefer
2022-11-07  5:35     ` [PATCH] " Bart Schaefer
2022-11-07  9:44       ` Peter Stephenson
2022-11-08  1:20         ` Bart Schaefer
2022-11-08  4:58     ` Philippe Altherr
2022-11-08  5:36       ` Bart Schaefer
2022-11-08  8:04         ` Lawrence Velázquez [this message]
2022-11-08 18:51           ` Philippe Altherr
2022-11-08 19:20             ` Lawrence Velázquez
2022-11-08 23:28             ` Bart Schaefer
2022-11-09  4:11               ` Philippe Altherr
2022-11-09  6:00                 ` Bart Schaefer
2022-11-09 14:22                   ` Philippe Altherr
2022-11-10  1:00                     ` Bart Schaefer
2022-11-10  5:09                       ` Bart Schaefer
2022-11-11  3:04                         ` Philippe Altherr
2022-11-11  4:06                           ` Lawrence Velázquez
2022-11-11  4:09                           ` Eric Cook
2022-11-08 23:11           ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1edb7786-f0b2-4830-88fa-99a19bda39e2@app.fastmail.com \
    --to=larryv@zsh.org \
    --cc=philippe.altherr@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).