Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: piping surprise
On Wed, Apr 3, 2024 at 11:49 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> I believe Bart had a solution to that.
I can't think what you're referring to, but in the realm of the baroque ...
typeset -gi Pnum
alias -g '|'='> ${TMPPREFIX}pipe$$.$((++Pnum)) ; < ${TMPPREFIX}pipe$$.$((Pnum))'
This uses global aliasing to replace the '|' token with I/O
redirection through a (relatively) uniquely named temporary file.
Only works if the left side actually finishes writing so that the
right side can start reading.
However, there's a bug (?) in that if you chain together several
commands this way, only the first $((++Pnum)) actually increments the
parameter, so all the commands end up with the same file names. E.g.
echo foo | tr a-z A-Z | cat
just prints "foo". You can see this by writing it all out and
inserting an extra "echo":
echo PIPE > pipe.$((++Pnum)); echo $Pnum;\
< pipe.$((Pnum)) cat > pipe.$((++Pnum)); echo $Pnum ; < pipe.$((Pnum)) cat
This will echo the same number twice, where it should echo consecutive
numbers. This only happens if the autoincrement appears in a
redirection.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author