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

Re: nohistsubstpattern and :s//



Peter, this is yours from way back in workers/22934 -- any memory left
from 2006?

On Jul 4,  3:22pm, Mikael Magnusson wrote:
} Subject: nohistsubstpattern and :s//
}
} % setopt histsubstpattern; a=(aaa bab cac) b=d; echo $a:s/a/${b}/
} daa bdb cdc

Hmm ... hist_subst_pattern doesn't say anything about expansions in
the replacement part of s/pat/rep/, so as far as I can tell this is
contrary to the documentation.  However, see below.

} % setopt nohistsubstpattern; a=(aaa bab cac) b=d; echo $a:s/a/${b}/
} ${b}aa b${b}b cdc

This has been like this for as long as the hist_subst_pattern option
has existed, it appears.  Random old builds I happen to have around
show behavior matching the doc in 3.0.6 and 3.0.8 --

torch% echo $ZSH_VERSION
3.0.6-pre-5
torch% a=(aaa bab cac) b=d; echo $a:s/a/${b}/
${b}aa b${b}b c${b}c

torch% echo $ZSH_VERSION
3.0.8
torch% a=(aaa bab cac) b=d; echo $a:s/a/${b}/
${b}aa b${b}b c${b}c

-- but then after hist_subst_pattern is added in 4.3.3 --

torch% echo $ZSH_VERSION                                                        
4.3.17-test-2
torch% a=(aaa bab cac) b=d; echo $a:s/a/${b}/
${b}aa b${b}b cdc

-- and (still 4.3.17-test-2) --

torch% setopt histsubstpattern
torch% a=(aaa bab cac) b=d; echo $a:s/a/${b}/
daa bdb cdc


So this undocumented behaver of the replacement has also been around
ever since the option was first implemented.  The original test case
in E01options.ztst even expects expansions in the replacement, so it
seems to have been intentional, to allow references to $match in the
event of backrefs in the pattern.

This also changed the behavior for scalars when hist_subst_pattern is
NOT set (note "g" added below):

torch% echo $ZSH_VERSION
3.0.8
torch% a="aaa bab cac" b=d; echo $a:gs/a/${b}/
${b}${b}${b} b${b}b c${b}c

torch% echo $ZSH_VERSION
4.3.17-test-2
torch% a="aaa bab cac" b=d; echo $a:gs/a/${b}/
ddd bdb cdc

So I suspect the same logic error (?) that changed this for scalars is
also somehow affecting the last element of an array.



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