zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [bug] wrong exit status upon (e) flag fatal errors in if/while conditions
Date: Wed, 5 May 2021 12:07:13 +0100	[thread overview]
Message-ID: <20210505110713.zmny7625vlmog6ir@chazelas.org> (raw)

$ a='${' zsh -c 'if : ${(e)a}; then echo x; fi; echo y'; echo $?
zsh:1: bad substitution
0
$ a='${' zsh -c 'if : ${(e)a}; then echo x; fi; echo y'; echo $?
zsh:1: bad substitution
0

That's when the (e) flag is used in the condition part of an
"if" or "while" (not "until") statement at least.

The shell aborts with an error message but with a success exit
status.

Also, the description of the X flag suggests that error should
be "silently ignored":

DOC> X
DOC>      With this flag, parsing errors occurring with the Q, e and # flags
DOC>      or the pattern matching forms such as '${NAME#PATTERN}' are
DOC>      reported.  Without the flag, errors are silently ignored.

See also:

$ a='$(echo ")' zsh -c 'if : ${(Xe)a}; then echo x; fi; echo y'; echo $?
zsh:1: unmatched "
zsh:1: parse error
0
$ a='$(echo ")' zsh -c 'if : ${(e)a}; then echo x; fi; echo y'; echo $?
zsh:1: unmatched "
x
y
0

Here, the X flag does have an effect, but an error is still
reported (even if it doesn't abort the shell) without it.

-- 
Stephane


             reply	other threads:[~2021-05-05 11:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 11:07 Stephane Chazelas [this message]
2021-05-05 11:47 ` Peter Stephenson

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=20210505110713.zmny7625vlmog6ir@chazelas.org \
    --to=stephane@chazelas.org \
    --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).