The following issue has been SUBMITTED.
======================================================================
http://austingroupbugs.net/view.php?id=114
======================================================================
Reported By: eblake
Assigned To: ajosey
======================================================================
Project: 1003.1(2008)/Issue 7
Issue ID: 114
Category: Shell and Utilities
Type: Omission
Severity: Comment
Priority: normal
Status: Under Review
Name: Eric Blake
Organization:
User Reference: ebb.dot
Section: dot
Page Number: 2341
Line Number: 74053
Final Accepted Text:
======================================================================
Date Submitted: 2009-07-01 16:55 UTC
Last Modified: 2009-07-01 16:55 UTC
======================================================================
Summary: dot exit status
Description:
The standard is unclear what happens to $? when an argument to . is not
found in an interactive shell. Line 74030 states that a diagnostic is
written but it is not a syntax error (which generally implies non-zero
status), but line 74053 states that the exit status is 0 if no command is
executed (and since no file was found, no command was executed). Existing
practice is that $? is set to non-zero in this case (although various
shells have chosen 1, 2, or 127).
In a similar vein, the standard appears to be silent on what happens when
., eval, or trap encounter text that cannot be parsed in isolation. In
this case, traditional shells either aborted with non-zero status, or
guaranteed non-zero status visible to subsequent commands; but some modern
shells do not detect the failure (which can be rather surprising):
$ echo 'if' > tmp
$ zsh -c 'emulate sh; . ./tmp; echo $?'
./tmp:1: parse error near `\n'
0
$ bash --posix -c 'trap "if" 0'; echo $?
bash: exit trap: line 1: syntax error: unexpected end of file
0
It would be nice to tighten this up (even though that renders some
existing implementations buggy).
Desired Action:
At line 74053 (dot), replace:
Returns the value of the last command executed, or a zero exit status if
no command is executed.
with:
If no readable file was found or if the commands in the file could not be
parsed, and the shell does not abort, the exit status shall be non-zero.
Otherwise, return the value of the last command executed, or a zero exit
status if no command is executed.
At line 74110 (eval), replace:
If there are no arguments, or only null arguments, eval shall return a
zero exit status; otherwise, it shall return the exit status of the command
defined by the string of concatenated arguments separated by <space>
characters.
with:
If there are no arguments, or only null arguments, eval shall return a
zero exit status; otherwise, it shall return the exit status of the command
defined by the string of concatenated arguments separated by <space>
characters, or a non-zero exit status if the concatenation could not be
parsed as a command and the shell did not abort.
At line 74864 (trap), replace:
The value of "$?" after the trap action completes shall be the value it
had before trap was invoked.
with:
If a trap action cannot be parsed at the time it is invoked, and the shell
does not abort, then the value of "$?" shall be non-zero; otherwise the
value of "$?" after the trap action completes shall be the value it had
before the trap action was invoked.
======================================================================
|