[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: POSIX shell specification insight requested

On Tue, Mar 02, 2004 at 03:04:49PM -0600, Manoj Srivastava wrote:
> On Tue, 2 Mar 2004 20:43:01 +0000, Colin Watson <cjwatson@debian.org> said: 
> > On Tue, Mar 02, 2004 at 12:47:15PM -0600, Manoj Srivastava wrote:
> >> -- A script consisting solely of redirections produces unspecified
> >> results
> >> ======================================================================
> >>
> >> The here document is a redirection, hence the reults of that
> >> command substitution are unspecified.
> > "cat <<EOF" is not "a script consisting solely of redirections". It
> > contains a redirection, but does not consist solely of one.
> 	I'll bite, Mr. bones. Please point out to dumb ol' me a single
>  statement in that script that is free of redirections. Or, if you
>  prefer POSIX syntax, please point me to a single "command" that is
>  free of redirection.

"A script consisting solely of redirections" is not the same as "a
script consisting solely of commands free of redirections". For example,
'> foo' is a command and consists solely of redirections: it has no
command name.

> 	Oh, BTW, what POSIX considers a command is defined in sections
>  §3.9.1 (simple) and § 3.9.4 (compound). But I'm sure you knew that.

I'm afraid I don't have access to the original POSIX, but I'm familiar
with the definitions in IEEE Std 1003.1-2001 POSIX.1 (a.k.a. SuSv3); I'm
inclined to doubt that they differ much in this regard, but I'm sure
somebody such as yourself with a copy could check. They say, among other

  A "simple command" is a sequence of optional variable assignments and
  redirections, in any sequence, optionally followed by words and
  redirections, terminated by a control operator.


  If there is no command name, any redirections shall be performed in a
  subshell environment; it is unspecified whether this subshell
  environment is the same one as that used for a command substitution
  within the command. (To affect the current execution environment, see
  the exec() special built-in.) If any of the redirections performed in
  the current shell execution environment fail, the command shall
  immediately fail with an exit status greater than zero, and the shell
  shall write an error message indicating the failure. See Consequences
  of Shell Errors for the consequences of these failures on interactive
  and non-interactive shells.

In this parlance, 'cat <<EOF' is a word (the command name) and a
redirection, and so doesn't consist solely of redirections. It's quite
clear that "redirection" is not synonymous with "command containing a


Colin Watson                                  [cjwatson@flatline.org.uk]

Reply to: