Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: command substitution: zsh waits until command exits



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