On Sunday 04 July 2010 17:11:11 Christoph Anton Mitterer wrote:
> I may have found a place where dash violates POSIX.
> 
> If I do the following:
> $ sh
> $ set -e
> $ false
> 
> it exits, as expected, and specified here
> http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set
> 
> 
> However, when doing the following:
> $ sh
> $ set -e
> $ . someNonExistentFile
> .: 2: foo: not found
> $
> 
> it does not exit.

I don't see any bug here, let me explain:

> Now the above documentation for -e says:
> When this option is on, if a simple command fails for any of the reasons
> listed in Consequences of Shell Errors or *returns an exit status value >0*,
> and is not part of the compound list following a while, until, or if
> keyword, and is not a part of an AND or OR list, and is not a pipeline
> preceded by the ! reserved word, then the shell shall immediately exit.
> 
> "." is described here
> (http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#d
> ot) where it says all the following:
> - If no readable file is found, a *non-interactive shell shall abort*; an
> *interactive shell shall write a diagnostic message to standard error*, but
> this condition shall not be considered a syntax error.
> -EXIT STATUS: Returns the value of the last command executed, or a zero
> exit status if no command is executed.

dash's manual page says:
> If no args are present and if the standard input of the shell is connected
> to a terminal (or if the -i flag is set), and the -c option is not present,
> the shell is considered an interactive shell.

So, in your example what you are running is _an interactive shell_. I would 
say that's the reason why dash doesn't abort: it is an interactive shell and 
since 'dot' didn't execute any command it returns a status code of 0.

$  dash -c 'set -e; . /dev/foo; echo Exited with status: $?'
.: 1: Can't open /dev/foo
$ 

Further confirmation:
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_08_01

HOWEVER, there's something interesting:
$ dash
$ PS1='dash$ '
dash$ . foo
.: 2: foo: not found
dash$ . /dev/foo
.: 3: Can't open /dev/foo
$

It exits even if it is an interactive shell. The only difference between the 
two is that '. foo' means "look for 'foo' in $PATH and execute its commands," 
while '. /dev/foo' means "execute /dev/foo's commands."

That IMO would be the bug.

(FTR, bash and others consider the former form as a combination of the two 
forms, i.e. they look for the argument in $PATH and if not found they look for 
it in ./)

The problem I see with that interpretation of POSIX, is that there's no way 
for a script to know if 'dot' failed because the file argument was not 
readable, even with set -e.

Btw, those links point to POSIX:2008, but Debian Policy requires SUSv3 (a.k.a. 
POSIX:2004.)

Cheers,
-- 
Raphael Geissert - Debian Developer
www.debian.org - get.debian.net



-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to