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

bar='#pat'; ${foo/$bar/...} problem



It seems to be impossible to specify `#' (and probably `%') as part of the
replaced pattern:

bor@itsrm2:/tools/src/zsh-3.1.5-pws-14%> zsh -f
itsrm2% foo=(xxya xxyb)
itsrm2% bar=('xx' 'zz')
itsrm2% print ${foo/$bar[1]/$bar[2]}
zzya zzyb
itsrm2% bar=('#xx' 'zz')
itsrm2% print ${foo/$bar[1]/$bar[2]}
xxya xxyb
itsrm2% print ${foo/$~bar[1]/$bar[2]}
xxya xxyb
itsrm2% setopt extendedglob
itsrm2% print ${foo/$bar[1]/$bar[2]}
xxya xxyb
itsrm2% print ${foo/$~bar[1]/$bar[2]}
zsh: bad pattern: #xx
itsrm2% bar=('\#xx' 'zz')
itsrm2% print ${foo/$~bar[1]/$bar[2]}
xxya xxyb
itsrm2% print ${foo/$bar[1]/$bar[2]}
xxya xxyb
itsrm2%

Only the frirst one yields the correct result. But I need exactly the
run-time pattern, that should match only at the beginning ...

cheers

/andrej



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