Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[BUG] 'command' + special built-in exits shell on error
- X-seq: zsh-workers 37425
- From: Martijn Dekker <martijn@xxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [BUG] 'command' + special built-in exits shell on error
- Date: Wed, 23 Dec 2015 11:53:22 +0000
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Special built-ins may cause the shell to exit on error. Sometimes this
is inconvenient as you cannot test for errors without forking a subshell.
POSIX provides a way around this: the 'command' builtin disables the two
"special built-in" properties of special built-ins, including exiting
from the shell on error.
This means:
set -o nonexistent_shell_option || echo oops
should produce only an error message and cause the shell to exit, whereas
command set -o nonexistent_shell_option || echo oops
should output "oops" after the error message and script execution should
continue.
My bug report is that zsh still exits even when 'command' is used, and
even when emulating sh.
bash, ksh93, mksh (as of R51), dash, FreeBSD /bin/sh, NetBSD /bin/sh,
Busybox ash, and yash all do the right thing, suggesting that this
should be fixed in zsh at least in 'emulate sh' mode.
References:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html#tag_20_22
> If the command_name is the same as the name of one of the special
> built-in utilities, the special properties in the enumerated list at
> the beginning of Special Built-In Utilities shall not occur.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_14
> [...] the special built-in utilities described here differ from
> regular built-in utilities in two respects:
>
> 1. A syntax error in a special built-in utility may cause a shell
> executing that utility to abort, while a syntax error in a regular
> built-in utility shall not cause a shell executing that utility to
> abort. (See Consequences of Shell Errors for the consequences of
> errors on interactive and non-interactive shells.) If a special
> built-in utility encountering a syntax error does not abort the
> shell, its exit value shall be non-zero.
>
> 2. Variable assignments specified with special built-in utilities
> remain in effect after the built-in completes; this shall not be the
> case with a regular built-in or other utility.
Thanks,
- M.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author