From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9278 invoked from network); 8 Feb 2002 09:29:59 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 8 Feb 2002 09:29:59 -0000 Received: (qmail 3167 invoked by alias); 8 Feb 2002 09:29:51 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16591 Received: (qmail 3156 invoked from network); 8 Feb 2002 09:29:50 -0000 Date: Fri, 8 Feb 2002 01:29:44 -0800 From: Derek Peschel To: zsh-workers@sunsite.dk Subject: Re: parameter substitution won't double backslashes in values Message-ID: <20020208012944.A8380@eskimo.eskimo.com> References: <20020207122222.A14893@eskimo.eskimo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: ; from schaefer@brasslantern.com on Thu, Feb 07, 2002 at 09:00:05PM +0000 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