From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2290 invoked by alias); 23 Dec 2015 12:01:16 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37425 Received: (qmail 11359 invoked from network); 23 Dec 2015 12:01:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 Message-ID: <567A8B32.9030300@inlv.org> Date: Wed, 23 Dec 2015 11:53:22 +0000 From: Martijn Dekker User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: zsh-workers@zsh.org Subject: [BUG] 'command' + special built-in exits shell on error Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit 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.