Subject: Re: correct shell behaviour?
To: <>
From: David Laight <david@l8s.co.uk>
List: tech-userlevel
Date: 08/11/2002 21:45:25
> ... but section 2.9.1 (Simple commands) explicitly says that
> normal words are expanded first, then redirections and finally variable
> assignments. I think 2.9.1, being more explicit, is correct.
>
> Hmm. That leads to another interesting test:
>
> x=$(echo var >&2) : >/dev/null$(echo redir >&2) $(echo arg >&2)
>
> I believe the correct output from this is:
>
> arg
> redir
> var
Section 2.9.1 does seem to imply that.
The last paragraph of it:
"If there is a command name, execution shall continue as described
in Command Search and Execution . If there is no command name, but
the command contained a command substitution, the command shall
complete with the exit status of the last command substitution
performed. Otherwise, the command shall complete with a zero exit
status."
also indicates that the exit status of the last substitution is
picked up only if there wasn't a command.
So:
a=`command`
echo $?
outputs the status of command, but that the status of command3
in:
command1
command2 `command3` $?
is discarded - so cannot be substituted in for the $?, which
must therefore still be the result of command1.
Now to fix sh.
David
--
David Laight: david@l8s.co.uk