zsh-users
 help / color / mirror / code / Atom feed
* parameter expansion with '$'
@ 2015-02-25 20:50 Kartik Agaram
  2015-02-25 21:18 ` Roman Neuhauser
  0 siblings, 1 reply; 3+ messages in thread
From: Kartik Agaram @ 2015-02-25 20:50 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 465 bytes --]

Hi,

Consider this example:

$ X=abc
$ echo ${X/c/}
ab

However, I'd like to only perform the substitution when 'c' occurs at the
end of the string:

$ echo ${X/c$/}
abc  # I'd like this to return 'ab' like above

I assume others see the same results? Can anybody help me understand why it
doesn't work, and how I can interpret the '$' as a regular expression
wildcard rather than some other sort of zsh sigil?

Thanks,
Kartik
zsh 5.0.5 on x86_64 with extendedglob

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

* Re: parameter expansion with '$'
  2015-02-25 20:50 parameter expansion with '$' Kartik Agaram
@ 2015-02-25 21:18 ` Roman Neuhauser
  2015-02-25 21:20   ` Kartik Agaram
  0 siblings, 1 reply; 3+ messages in thread
From: Roman Neuhauser @ 2015-02-25 21:18 UTC (permalink / raw)
  To: Kartik Agaram; +Cc: zsh-users

# ak@akkartik.com / 2015-02-25 12:50:16 -0800:
> I'd like to only perform the substitution when 'c' occurs at the
> end of the string:
> 
> $ echo ${X/c$/}
> abc  # I'd like this to return 'ab' like above
> 
> I assume others see the same results? Can anybody help me understand why it
> doesn't work, and how I can interpret the '$' as a regular expression
> wildcard rather than some other sort of zsh sigil?

these patterns are *not* regular expressions.  zshexpn(1) says near
the start of PARAMETER EXPANSION:

  In the expansions discussed below that require  a pattern, the  form
  of the pattern is the same as that used for filename generation; see
  the section `Filename Generation'.

  ${name/pattern/repl}
  ${name//pattern/repl}
      [...]

      The pattern may begin with a `#', in which case the pattern must
      match at the start of the string, or `%', in which case it  must
      match  at  the end of the string, or `#%' in which case the pat-
      tern must match the entire string. [...] Note also that the `#',
      `%' and `#%' are  not  active if they occur inside a substituted
      parameter, even at the start.

-- 
roman


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

* Re: parameter expansion with '$'
  2015-02-25 21:18 ` Roman Neuhauser
@ 2015-02-25 21:20   ` Kartik Agaram
  0 siblings, 0 replies; 3+ messages in thread
From: Kartik Agaram @ 2015-02-25 21:20 UTC (permalink / raw)
  To: Roman Neuhauser; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 17 bytes --]

Ah, many thanks.

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

end of thread, other threads:[~2015-02-25 21:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-25 20:50 parameter expansion with '$' Kartik Agaram
2015-02-25 21:18 ` Roman Neuhauser
2015-02-25 21:20   ` Kartik Agaram

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).