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

Re: first adventures



On Fri, 31 Oct 2014 11:10:54 -0700
Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> One further question, I tried the ' (Q) ' flag to remove quotes, and it 
> works
> as advertised, however trying to print individual array elements fails 
> whereas
> they print fine with the ' (z) 'flag.  Why is that?

They're doing different things.  (Q) really does just remove quotes, it
doesn't split things into elements.  (z) splits things into elements
using the shell's normal rules, but doesn't remove quotes.

You might be running up against the problem that if you combine them in
the obvious way it doesn't do what you want because the splitting
happens too late.  That's a deliberate rule, it's just not convenient in
this particular case --- there are so many cases for parameter expansion
it's quite impossible to get them all to work in the simplest way.

So starting with

% print -rl ${line}   
'one two' "buckle my shoe" three\ four

(printing the raw string arguments one per line) you get

% print -rl ${(Qz)line}
one
two
buckle
my
shoe
three
four

which isn't what you want.  But you can use a nested expansion to get
the quotes removed after zplitting:

% print -rl ${(Q)${(z)line}}
one two
buckle my shoe
three four

Finally, you've got exactly the right set of arguments as simple strings.

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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