Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: command substitution: zsh waits until command exits
- X-seq: zsh-users 12279
- From: Vincent Lefevre <vincent@xxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: command substitution: zsh waits until command exits
- Date: Tue, 4 Dec 2007 02:42:27 +0100
- In-reply-to: <071203092626.ZM4367@xxxxxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20071130133943.GG5855@xxxxxxxxxxxxxxxxxxx> <071130073719.ZM18090@xxxxxxxxxxxxxxxxxxxxxx> <20071130163155.GL5855@xxxxxxxxxxxxxxxxxxx> <071130185827.ZM18402@xxxxxxxxxxxxxxxxxxxxxx> <20071202021652.GO5855@xxxxxxxxxxxxxxxxxxx> <071201210744.ZM20044@xxxxxxxxxxxxxxxxxxxxxx> <20071202152254.GP5855@xxxxxxxxxxxxxxxxxxx> <071202102717.ZM2757@xxxxxxxxxxxxxxxxxxxxxx> <20071203011131.GT5855@xxxxxxxxxxxxxxxxxxx> <071203092626.ZM4367@xxxxxxxxxxxxxxxxxxxxxx>
On 2007-12-03 09:26:24 -0800, Bart Schaefer wrote:
> If the shell were not obligated to wait, it wouldn't have the exit
> status of the command substitution, and it would be unclear what is
> meant by "the last performed." It would be unreasonable to expect
> that command substitutions behave asynchronously only in the absence
> of a non-command-substitution in the command word position.
OK (though POSIX -- and the zsh manual -- should probably make this
more clear).
Now, if I understand correctly,
$(false) && echo true
shouldn't output anything because before the &&, there's no command
and the command substitution has a non-zero exit status. On this
example, bash, dash and ksh93 behave correctly, but not zsh (with
the version provided by Debian/unstable).
> Also in 2.9.1, it says that
>
> 2. The words that are not variable assignments or redirections shall
> be expanded ...
>
> and then
>
> 4. Each variable assignment shall be expanded ...
>
> (If I previously knew that, I'd forgotten.) Thus
>
> rm -f /tmp/first
> LAST=$(cat /tmp/first) printenv $(echo LAST & echo first > /tmp/first)
>
> is IMO required to output "first", which again would not be determinable
> if command substitution were not waited for. Zsh gets this one right.
Well, for this particular point, POSIX doesn't explicitly require the
above to be determinable, IMHO.
> } > echo $(coproc xterm -e 'zsh -fic "tty >&3 ; exec sleep 999999"' 3>&1 ;
> } > read -E <&p)
> } >
> } > Or this, which doesn't rely on coproc:
> } >
> } > echo $({ xterm -e 'zsh -fic "tty >&3 ; exec sleep 999999"' 3>&1 & } |
> } > read -E)
> }
> } Both are working. Is there one of them that is better?
>
> Not really. The second one is more portable, except for the
> reference to zsh.
This is what I thought and why I tried with sh, but this didn't work
with sh.
--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author