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

Re: Count only visible characters?



On Fri, 9 Apr 2010 12:56:02 +0200
Sebastian Stark <seb-zsh@xxxxxxxxxxx> wrote:
> print "${(%)a::=%F{green}hello}"
> hello}
> % print "${(%)a::=%F{green}hello"
> hello
>
> Why does the first print statement print the closing brace? How can the
> second print statement not produce an error?

${...} doesn't attempt to balance braces internally, so the first } brings
it to an end.  The final quoted "}" is then just an ordinary character.

You're being a bit too clever for your own good here by trying to too much
at once.  If you separate out the assignment from the use it'll work.
If you absolutely have to do it this way, however, quoting the text you
want to be treated as a string by the parameter expansion works.

print "${(%)a::="%F{green}hello"}"

The outer double quotes are now overloaded too many times to be able to
tell this is what you mean: see a recent post by Bart for a reference to a
discussion on the standards mailing list about trouble with double quotes.
I'm not sure you actually want the outer double quotes at all, but I'm not
sure what you're trying to do (and it probably doesn't matter for this
particular issue).

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



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