From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: piping surprise
Date: Fri, 5 Apr 2024 16:32:14 -0400 [thread overview]
Message-ID: <CAH+w=7bVTMo3+qQBMSF0mL1rneoFDuVh_-w-ToCsnmW8gZQW=w@mail.gmail.com> (raw)
In-Reply-To: <f53e52b4-baed-427f-b2bd-8f72a0553934@eastlink.ca>
On Wed, Apr 3, 2024 at 11:49 AM Ray Andrews <rayandrews@eastlink.ca> 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.
next prev parent reply other threads:[~2024-04-05 20:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-03 13:17 Ray Andrews
2024-04-03 15:00 ` Mikael Magnusson
2024-04-03 15:49 ` Ray Andrews
2024-04-05 20:32 ` Bart Schaefer [this message]
2024-04-05 23:11 ` Ray Andrews
2024-04-07 6:34 ` Lawrence Velázquez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAH+w=7bVTMo3+qQBMSF0mL1rneoFDuVh_-w-ToCsnmW8gZQW=w@mail.gmail.com' \
--to=schaefer@brasslantern.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).