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

Re: Bad "bad pattern" in ${foo//pat/repl} ?



almost a year ago, Bart Schaefer added the following note to the email 
archives:

================================================
From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
To: zsh-workers@xxxxxxxxxx
Subject: Bad "bad pattern" in ${foo//pat/repl} ?
Date: Sat, 13 Jul 2002 21:35:31 +0000
Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
 
(Never mind why the elements of $foo have spaces in them, I was fooling
with something else when I came across this.)

schaefer<501> foo=("a b" "a c" "b q" "x y")                                    
schaefer<502> echo ${foo/#a*/yes}
yes yes b q x y
schaefer<503> echo ${foo//#a*/yes} 
a b a c b q x y
schaefer<504> setopt extendedglob 
schaefer<505> echo ${foo/#a*/yes}
yes yes b q x y
schaefer<506> echo ${foo//#a*/yes}    
zsh: bad pattern: #a*

Surely both 503 and 506 are bugs (probably the same bug).  One should be able
to anchor to the beginning of the string even when doing a replace-all (I do
admit it doesn't really make sense to do so, but ...).

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com
================================================

with 4.1.1-test-3, I am still getting the same erroneous error message for 
beginning of string operator (#), and a no-op for the end of string operator 
(%).  in each of the following examples, extendedglob is set.

03-06-04
16:44:44 [514] bubo7:scripts/zsh% a="    a b c d     " ; s=" " ; r="" ; \ 
printf "a: >%s<\n" ${a//#${s}/${r}}  
zsh: bad pattern: #
03-06-04
16:44:55 [515] bubo7:scripts/zsh% a="    a b c d     " ; s=" " ; r="" ; \ 
printf "a: >%s<\n" ${a//%${s}/${r}}   
a: >    a b c d     <

if they worked, these operations would be superb for left and right string 
trims.  the work around I've chosen is to use the read builtin to do the 
whitespace trims.  for non-whitespace trims, however, the problem remains.  
does anyone have a workaround?

scowles at earthlink dot net





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