Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Possible bug with $~pattern, (#mi)
On Oct 7, 4:39pm, Peter Stephenson wrote:
} Subject: Re: Possible bug with $~pattern, (#mi)
}
} On Wed, 7 Oct 2015 17:28:04 +0200
} Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
} > first one and third one are the same, but only first invocation works.
} > Not sure if second one should work:
} >
} > # a="1234"; beg="#" echo ${a/$~beg(#mi)1/-}
} > -234
} > # a="1234"; beg="#"; num=1; echo ${a/$~beg(#mi)$~num/-}
} > zsh: bad pattern: #(#mi)1
}
} The difference is the first one doesn't have $beg defined at the point
} where the expansion takes place
OK, but what I think he's trying to achieve is
% a="1234"
% b="4321"
% print ${a/#(#mi)1/-} ${b/#(#mi)1/-}
-234 4321
which works and treats the first "#" as part of the ${var//} expansion
rather than as part of the pattern.
So the complete answer is that there is no way to dynamically insert
the beginning marker # or end marker % in ${a/#p/r} or ${a/%p/r} --
they must appear literally, otherwise they become part of the pattern.
If you want to do this dynamically, you have to use the extendedglob
anchoring syntax rather than the parameter expansion anchoring syntax:
% beg='(#s)'
% print ${a/$~beg(#mi)1/-}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author