Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Count only visible characters?
- X-seq: zsh-users 14994
- From: Sebastian Stark <seb-zsh@xxxxxxxxxxx>
- To: Peter Stephenson <pws@xxxxxxx>
- Subject: Re: Count only visible characters?
- Date: Fri, 9 Apr 2010 14:27:10 +0200
- Cc: zsh-users@xxxxxxx
- In-reply-to: <20100409130844.67ee0d5b@news01>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <loom.20100409T002951-342@xxxxxxxxxxxxxx> <201004091102.55291.joke@xxxxxxxxx> <87d3y90z07.fsf@xxxxxxxxxxxxxxxxxxxxxx> <D623EAB5-E787-4381-9DB8-42C6E3C3FD1D@xxxxxxxxxxx> <E9EE686F-6566-4827-B6D9-36BA86FA65A4@xxxxxxxxxxx> <20100409130844.67ee0d5b@news01>
Am 09.04.2010 um 14:08 schrieb Peter Stephenson:
> 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.
ok, good to know.
> 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.
The expression works as I expect when I leave out all the double quotes. I didn't think those were the problem.
> 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).
Sometimes I want to use expansions that are only available as prompt expansions. It's a bit cumbersome having to assign them to a variable first and then evaluate it with the %-modifier. One example would be a condition that checks wether a background job is running:
if ((${(%):-%j}))
then
print "no reexec because background job is running"
return $E_JOB
fi
In this example the above is not an issue. But it could appear in other contexts, when using "inline prompt expansion" in print statements. I admit this is a bit esoteric, but still worth mentioning.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author