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

Re: piping surprise



On Fri, Apr 5, 2024, at 4:32 PM, Bart Schaefer wrote:
> 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".

And sometimes the parameter is not incremented at all:

	% (echo foo) | tr a-z A-Z | cat
	zsh: no such file or directory: /tmp/zshpipe39158.0
	zsh: no such file or directory: /tmp/zshpipe39158.0
	% cat <<<foo | tr a-z A-Z | cat
	zsh: no such file or directory: /tmp/zshpipe39158.0
	zsh: no such file or directory: /tmp/zshpipe39158.0
	% typeset -p Pnum
	typeset -i Pnum=0

But:

	% echo foo | { tr a-z A-Z } | cat
	FOO
	% typeset -p Pnum
	typeset -i Pnum=2

-- 
vq




Messages sorted by: Reverse Date, Date, Thread, Author