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

Re: parameter expansion, substitution



On 9 March 2012 23:03, S. Cowles <scowles@xxxxxxxx> wrote:
> i am not getting expected results in the following code snippet:
>        b="abc" ; b=${b/#abc%/d} ; echo ${b}
> i expect the value of b to be changed to "d"; however, it remains "abc".
>
> the following snippet does give the expected result:
>        b="abc" ; b=${b/#abc/d} ; echo ${b}
>
> for this session, the following shell options are set: interactive monitor
> shinstdin zle.  the version of the shell being used is 4.3.17-dev-0,
> patchlevel 1.5604.
>
> in my use case, i need to specify a pattern match at the end of the
> parameter.  have i misunderstood the syntax of the '%' end-of-string
> operator?  or is this problem something else?
>
> thanks for any help.

It's possibly a bit counterintuitive, but both # and % go at the start
of the string, so you want
b=${b/#%abc/d}

-- 
Mikael Magnusson



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