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

Re: nohistsubstpattern and :s//



On Tue, 7 Jul 2015 08:48:51 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> So with histsubstpattern set it looks like $b is expanded before the
> substitution takes place, but with nohistsubstpattern (the default,
> which is why I never showed the option change in any of my previous
> examples) the expansion happens after the substitution.

Oh, in that case it's perfectly sensible.  The only gotcha is to
remember that because modifiers operate on raw input, which is how they
came to exist in the first place, if you don't want a $ to be active you
need to quote it.

% print ${a:gs/b/\$b/}
a$bc d$be f$bg

Not wanting this effect is probably a sign you should be using

% print ${a//b/$b}

where the rules are roughly "if it quacks like a single word, it's
expanded like a single word", so any expansion is always done (or
suppressed) within the substitution argument, and you get

% print ${a//b/$b}
ac de fg
% print ${a//b/\$b}
a$bc d$be f$bg

pws



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