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

Re: piping surprise



On Wed, Apr 3, 2024 at 3:19 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> Speaking of female logic, I stumbled upon this:

Keep your sexism to yourself, although in this case you're just
insulting yourself anyway.

> function bbb ()
> {
>     vvar=4
>     print -l "\nShall\nI\ncompare thee\nto a\nsummer's day?"
> }
>
> function aaa ()
> {
>     local vvar=1
>     bbb
>     echo "\nvvar is $vvar"
>     vvar=2
>     echo "\n=============\n"
>     bbb | grep 'a'
>     echo "\nvvar is $vvar"
> }
>
> %  aaa
>
> Shall
> I
> compare thee
> to a
> summer's day?
>
> vvar is 4
>
> =============
>
> Shall
> compare thee
> to a
> summer's day?
>
> vvar is 2
>
> ------------------------------------------------------------------
>
> By what thinking does the piping of a function's output thru grep cancel the assignment to the variable?  Do we really want that?

Surely by now you know how pipes work? One process has to run on
either side of the pipe, only one of them can be your current shell
(the one on the left is not it).

-- 
Mikael Magnusson




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