Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
(Fwd) [shell] posix conformance for special built-ins
- X-seq: zsh-workers 19704
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: (Fwd) [shell] posix conformance for special built-ins
- Date: Tue, 30 Mar 2004 00:04:26 +0000
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
--- Forwarded mail from David Korn <dgk@xxxxxxxxxxxxxxxx>
Date: Mon, 29 Mar 2004 10:00:27 -0500 (EST)
From: David Korn <dgk@xxxxxxxxxxxxxxxx>
To: shell@xxxxxxxxxxxxxxxx
Subject: [shell] posix conformance for special built-ins
Subject: posix conformance for special built-ins
--------
Here is an excerpt from mail from a user that shows different results
for different shells.
>
> In two places, I have a construct like this:
>
> . foo || source foo || true
>
> To my surprise, in testing I found that ksh bails out with an error if
> foo does not exist, rather than simply succeeding because of the true
> at the end of the conditional. Here is what I found for various shells:
>
> $ ksh88
> $ . foo || source foo || true
> /bin/ksh: foo: not found
> $ echo $?
> 1
>
> $ ksh93
> $ . foo || source foo || true
> /bin/ksh: foo: not found
> $ echo $?
> 1
>
> $ bash
> $ . foo || source foo || true
> bash: foo: No such file or directory
> bash: foo: No such file or directory
> $ echo $?
> 0
>
> $ zsh
> % . foo || source foo || true
> .: no such file or directory: foo
> source: no such file or directory: foo
> % echo $?
> 0
>
> % /bin/sh
> $ . foo || source foo || true
> foo: not found
> $ echo $?
> 1
>
> % pdksh
> $ . foo || source foo || true
> pdksh: .: foo: not found
> $ echo $?
> 1
>
> $ csh
> . foo || source foo || true
> /usr/local/bin/.: Permission denied.
> foo: No such file or directory
> echo $status
> 1
>
> $ tcsh
> % . foo || source foo || true
> /usr/local/bin/.: Permission denied.
> foo: No such file or directory.
> % echo $status
> 1
>
> So, is the behavior of ksh88 and ksh93 in ". foo || source foo || true"
> a bug or a feature?
>
> -----------------------------------------------------------------------------
> - Nelson H. F. Beebe Tel: +1 801 581 5254
> - University of Utah FAX: +1 801 581 4148
> - Department of Mathematics, 110 LCB Internet e-mail: beebe@xxxxxxxxxxxxx
> - 155 S 1400 E RM 233 beebe@xxxxxxx beebe@xxxxxxxxxxxx
> - Salt Lake City, UT 84112-0090, USA URL: http://www.math.utah.edu/~beebe
> -----------------------------------------------------------------------------
>
This behavior is required by the POSIX and X/Open standards. In section
section 2.8.1 of the 1003.1-2001 standard it states,
"For a non-interactive shell, an error condition encountered by a
special built-in shall cause the shell to write a diagnostic message
to standard error and exit as shown in the following table:"
In the following table, it lists Dot script not found, "Shall Exit".
While I don't like this behavior, it was inherited from the Bourne shell.
The standard added 'command' to get around this behavior, so that
command . foo || source foo || true
would give you the behavior that you want.
So unless we can get the standard changed we are stuck with this behavior.
Thus, bash and zsh are non-conforming. It would be nice to say that
the shell only bails out in cases for which set -e would have caused
it to exit, but this would require a change to the standard.
David Korn
dgk@xxxxxxxxxxxxxxxx
_______________________________________________
shell mailing list
shell@xxxxxxxxxxxxxxxx
https://mailman.research.att.com/mailman/listinfo/shell
---End of forwarded mail from David Korn <dgk@xxxxxxxxxxxxxxxx>
--- Forwarded mail from chet@xxxxxxxxxxx
Date: Mon, 29 Mar 2004 11:37:35 -0500
From: Chet Ramey <chet@xxxxxxxxxxxxxxxxxx>
To: dgk@xxxxxxxxxxxxxxxx
Subject: Re: [shell] posix conformance for special built-ins
Cc: shell@xxxxxxxxxxxxxxxx
Reply-To: chet@xxxxxxxxxxx
> This behavior is required by the POSIX and X/Open standards. In section
> section 2.8.1 of the 1003.1-2001 standard it states,
> "For a non-interactive shell, an error condition encountered by a
> special built-in shall cause the shell to write a diagnostic message
> to standard error and exit as shown in the following table:"
> In the following table, it lists Dot script not found, "Shall Exit".
>
> While I don't like this behavior, it was inherited from the Bourne shell.
> The standard added 'command' to get around this behavior, so that
> command . foo || source foo || true
> would give you the behavior that you want.
>
> So unless we can get the standard changed we are stuck with this behavior.
> Thus, bash and zsh are non-conforming. It would be nice to say that
> the shell only bails out in cases for which set -e would have caused
> it to exit, but this would require a change to the standard.
This is one of the things bash enables in `posix mode'.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
Live...Laugh...Love
Chet Ramey, ITS, CWRU chet@xxxxxxxxxxx http://tiswww.tis.cwru.edu/~chet/
_______________________________________________
shell mailing list
shell@xxxxxxxxxxxxxxxx
https://mailman.research.att.com/mailman/listinfo/shell
---End of forwarded mail from chet@xxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author