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

Re: Little doubt about an expansion flag



    Hi Wayne :)

 * Wayne Davison <wayned@xxxxxxxxxxxxxxxxxxxxx> dixit:
> >     and I'm looking (deciphering is more appropriate) at the first
> > part, namely ${(f)"$(ps xh)"}. When doing this, the output of the ps
> > command is *joined*, deleting the \n characters!!!
> Nope, the \n characters are not deleted because of the double quotes.

    Not exactly in this case... The problem was the 'echo' command I
was using. With 'print -l', which outputs *elements* separated by
whitespace, I can see that the (f) modifier is splitting the output
of the ps command into the lines and not into the spaces, so we can
do the matching on complete lines.

    Now I understand it, thanks to print -l :)))

> Try this:
>     echo "$(ps xh)"
> You'll see that they are still there.

    But the (f) modifier strips then and do splitting on them, and
not in words... When using echo I was using double quotes. I mean,
when doing the command (ps or whatever), let's have 'foo bar\nfoo2
bar2\nlastline' as output. Well, then we have:

    $echo $(command)
    foo bar foo2 bar2 lastline

    $echo "$(command)"
    foo bar
    foo2 bar2
    lastline

    $echo "${(f)"$(command"}"
    foo bar foo2 bar2 lastline

    $print -l "${(f)"$(command"}"
    foo bar
    foo2 foo2
    lastline
    

    What I didn't understand was the last 'echo' command, before the
'print -l' one. That's because echo has no idea about elements and
the like, print has. Now I understand all this. I should get used to
employ 'print' instead of 'echo', definitely ;)))

> >     Finally, I would like to know how the shell manages to parse
> > this: "${(f)"$(ps xh)"}", because it seems that the shell can read my
> > mind and parses the quotes nested, and not like "${(f)" $(ps xh) "}".
> Yes, this happens inside ${...} -- quotes start over in their nesting.

    OK, gotcha, thanks a lot for explaining :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/



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