Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: parameter substitution won't double backslashes in values
- X-seq: zsh-workers 16591
- From: Derek Peschel <dpeschel@xxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: parameter substitution won't double backslashes in values
- Date: Fri, 8 Feb 2002 01:29:44 -0800
- In-reply-to: <Pine.BSF.4.40.0202072033570.37987-100000@xxxxxxxxxxxxxxxx>; from schaefer@xxxxxxxxxxxxxxxx on Thu, Feb 07, 2002 at 09:00:05PM +0000
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20020207122222.A14893@xxxxxxxxxxxxxxxxx> <Pine.BSF.4.40.0202072033570.37987-100000@xxxxxxxxxxxxxxxx>
On Thu, Feb 07, 2002 at 09:00:05PM +0000, Bart Schaefer wrote:
> On Thu, 7 Feb 2002, Derek Peschel wrote:
> > Maybe my explanation was too complicated, or probably you missed the
> > beginning of the thread.
>
> I saw the beginning of the thread, and I saw Sven's answer, which didn't
> seem to bear repeating, so I was responding only to the parenthetical
> comment about backspace changing to "\b". As Sven's answer apparently
> does bear repeating:
Thanks for clearing that up. I apologize if I was a bit rude. Sven's
answer is the most practical for my needs.
> However, (q) will also insert a backslash in front of any other character
> that is special to the shell parser. If you want *only* to double all the
> backslashes, you need one of:
>
> zsh% print -r ${x//\\\/\\\\}
> a\\bc
> zsh% print -r ${x:gs/\\/\\\\\\\\}
> a\\bc
>
> The reason you need three backslashes as the pattern in the first case is
> rather complicated and could possibly be considered a bug; it has to do
> with using glob-pattern interpretation in ${x//...}. The reason you need
I was afraid of this... parameter expansion is obviously a complicated
operation. (I took "BUG? - " out of the subject because I haven't found
a problem that I know how to identify or fix. But not being able to
understand the syntax is somewhat of a bug in itself.)
For example, I only have a guess as to why these examples do what they do.
> x="/usr/home/dpeschel"
> print ${(q)x//t}
/usr/home/dpeschel
> print ${(q)x/\/t}
t/usr/home/dpeschel
The first example has "//" (as in global search-and-replace) followed by
a search pattern of "t", without the "/" to delimit the replacement pattern
or the pattern itself.
The second example has "/" (as in non-global search-and-replace) followed
by an empty search pattern, then "\/" which ends the search pattern,
then a replacement pattern of "t".
Is this true?
-- Derek
Messages sorted by:
Reverse Date,
Date,
Thread,
Author