Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: nohistsubstpattern and :s//
Sorry to keep coming back to this ...
On Jul 7, 11:10am, Bart Schaefer wrote:
}
} Not exactly the only gotcha. The after vs. during difference is a the
} least worth mentioning, particularly because of this:
}
} torch% print *a*
} config.modules.local config.status Makefile stamp-h
} torch% x=':gs/(#b)(?)?/X$match/'
} torch% setopt histsubstpattern extendedglob
} torch% print *a*($x)
} XcXnXiX.XoXuXeX.XoXa XcXnXiX.XtXts XMXkXfXl XsXaXph
OK, this is even more confusing:
torch% setopt histsubstpattern
torch% x=1
torch% !s:gs/t/$[x++]/:p
se1op1 his1subs1pa11ern
torch% a="setopt histsubstpattern"
torch% print ${a:gs/t/$[x++]/}
se2op2 his2subs2pa22ern
torch% setopt extendedglob
torch% print ${a:gs/(#b)t(?)/$match$[x++]/}
seo3p 4hiss5ubsp6at7ern
torch% print ${a:gs/t/$[x++]/}
se8op8 his8subs8pa88ern
torch% print ${a:gs/(#b)t(?)/$[x++]/}
se9p10his11ubs12a13ern
torch% !s:gs/(#b)t(?)/$[x++]/:p
se13p14his15ubs16a17ern ex18ndedglob
Not surprising that unlike no_hist_subst_pattern, history references
expand variables in the replacement. What IS surprising is that
when there are backreferences, $match and $[x++] are evaluated for
each replacement, even if $match is not mentioned. When there are
no backreferences, $[x++] is evaluated only once.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author