zsh-workers
 help / color / mirror / code / Atom feed
* parameter expansion, substitution
@ 2012-03-09 22:03 S. Cowles
  2012-03-09 22:25 ` Mikael Magnusson
  2012-03-09 22:27 ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: S. Cowles @ 2012-03-09 22:03 UTC (permalink / raw)
  To: zsh-workers

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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: parameter expansion, substitution
  2012-03-09 22:03 parameter expansion, substitution S. Cowles
@ 2012-03-09 22:25 ` Mikael Magnusson
  2012-03-09 22:48   ` S. Cowles
  2012-03-09 22:27 ` Bart Schaefer
  1 sibling, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2012-03-09 22:25 UTC (permalink / raw)
  To: S. Cowles; +Cc: zsh-workers

On 9 March 2012 23:03, S. Cowles <scowles@ckhb.org> 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: parameter expansion, substitution
  2012-03-09 22:03 parameter expansion, substitution S. Cowles
  2012-03-09 22:25 ` Mikael Magnusson
@ 2012-03-09 22:27 ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2012-03-09 22:27 UTC (permalink / raw)
  To: zsh-workers

On Mar 9,  2:03pm, S. Cowles wrote:
} Subject: parameter expansion, substitution
}
} 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".

You've misunderstood.  You want:

  	b="abc" ; b=${b/#%abc/d} ; echo ${b}

The # or % or #% must appear at the beginning of the pattern, they are
not positional like ^ and $ in a regular expression.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: parameter expansion, substitution
  2012-03-09 22:25 ` Mikael Magnusson
@ 2012-03-09 22:48   ` S. Cowles
  0 siblings, 0 replies; 4+ messages in thread
From: S. Cowles @ 2012-03-09 22:48 UTC (permalink / raw)
  To: zsh-workers


many thanks to you both, Bart and Mikael.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-03-09 22:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-09 22:03 parameter expansion, substitution S. Cowles
2012-03-09 22:25 ` Mikael Magnusson
2012-03-09 22:48   ` S. Cowles
2012-03-09 22:27 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).