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

[BUG] 'command' + special built-in exits shell on error

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

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.


> 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.

> [...] 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.


- M.

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