zsh-workers
 help / color / mirror / code / Atom feed
From: Martijn Dekker <martijn@inlv.org>
To: zsh-workers@zsh.org
Subject: [BUG] 'command' + special built-in exits shell on error
Date: Wed, 23 Dec 2015 11:53:22 +0000	[thread overview]
Message-ID: <567A8B32.9030300@inlv.org> (raw)

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.


             reply	other threads:[~2015-12-23 12:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-23 11:53 Martijn Dekker [this message]
2015-12-25  8:12 ` 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=567A8B32.9030300@inlv.org \
    --to=martijn@inlv.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).