* (Fwd) [shell] posix conformance for special built-ins
@ 2004-03-30 0:04 Bart Schaefer
0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2004-03-30 0:04 UTC (permalink / raw)
To: zsh-workers
--- Forwarded mail from David Korn <dgk@research.att.com>
Date: Mon, 29 Mar 2004 10:00:27 -0500 (EST)
From: David Korn <dgk@research.att.com>
To: shell@research.att.com
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@math.utah.edu
> - 155 S 1400 E RM 233 beebe@acm.org beebe@computer.org
> - 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@research.att.com
_______________________________________________
shell mailing list
shell@research.att.com
https://mailman.research.att.com/mailman/listinfo/shell
---End of forwarded mail from David Korn <dgk@research.att.com>
--- Forwarded mail from chet@po.cwru.edu
Date: Mon, 29 Mar 2004 11:37:35 -0500
From: Chet Ramey <chet@caleb.ins.cwru.edu>
To: dgk@research.att.com
Subject: Re: [shell] posix conformance for special built-ins
Cc: shell@research.att.com
Reply-To: chet@po.cwru.edu
> 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@po.cwru.edu http://tiswww.tis.cwru.edu/~chet/
_______________________________________________
shell mailing list
shell@research.att.com
https://mailman.research.att.com/mailman/listinfo/shell
---End of forwarded mail from chet@po.cwru.edu
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-03-30 0:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-30 0:04 (Fwd) [shell] posix conformance for special built-ins Bart Schaefer
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).