Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[bug] wrong exit status upon (e) flag fatal errors in if/while conditions



$ 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




Messages sorted by: Reverse Date, Date, Thread, Author