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

Re: Is ":G" of ${name:s/l/r/:G} actually supported?



Well, that was a shorter reply than I intended. But you should be able to see that the section you linked (14.1.4 Modifiers) is part of 14.1, History Expansion. Those modifiers don't apply to parameter substitution.

For doing replacements with parameter expansion, you can just use the slash modifier. One / replaces the first occurrence, two //s does all of them:

$ value=/dir/subdir/file.csv
$ echo ${value//dir/_G}
/_G/sub_G/file.csv
 
That's not a zsh-specific feature; ksh and bash have it as well. Zsh likely has a different mechanism to accomplish the same thing, but I've not needed it so am not familiar with it.
--
Mark J. Reed <markjreed@xxxxxxxxx>


On Mon, Feb 12, 2024 at 12:02 Mark J. Reed <markjreed@xxxxxxxxx> wrote:
That's history substitution, not parameter expansion:

$ ls foobar
...
$ !!:s/o/e/:G
ls feebar


On Mon, Feb 12, 2024 at 9:19 AM Joachim Ansorg <mail@xxxxxxxxxxxxxxx> wrote:
Hi,
I was reading about modifiers on page
https://zsh.sourceforge.io/Doc/Release/Expansion.html#Modifiers, which says:

>   The forms ‘gs/l/r’ and ‘s/l/r/:G’ perform global substitution, i.e. substitute every occurrence of r for l. Note that the g or :G must appear in exactly the position shown.

But zsh 5.9 doesn't seem to support this:
  > value="/dir/subdir/file.csv"
  > echo ${value:s/dir/_/:G}
  zsh: unrecognized modifier `G'

Is ":G" actually supported or is the documentation outdated here?
I might be overlooking something very simple, though.

Thank you!
Joachim Ansorg
--
BashSupport Pro
https://www.bashsupport.com/



--
Mark J. Reed <markjreed@xxxxxxxxx>


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