@replace weirdness

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Oct 29, 2008
83
0
#1
I’m trying to make an esc function for echoing stuff containing special chars without having to use quotes.

Why does
Code:
echo %@replace[^|,^^|,%@replace[^^,^^^^,foo|bar]]
evaluate to
Code:
foo^^|bar
?

It seems to be doing the ^ replacement after doing the | replacement.
Code:
echo %@replace[^|,^^|,foo|bar]
evaluates to
Code:
foo^|bar
as expected. My full esc function works as expected if the ^ replacement is omitted.
Code:
27.6G C:\Users\johnb\tmp> eset /f esc
esc=%@replace[^>,^^>,%@replace[^<,^^<,%@replace[^&,^^&,%@replace[^|,^^|,%$]]]]

27.6G C:\Users\johnb\tmp> echo %@esc[&|<>]
&|<>
(n.b. To enter this function at the command line, double all ^s)
Code:
function esc=`%@replace[^^>,^^^^>,%@replace[^^<,^^^^<,%@replace[^^&,^^^^&,%@replace[^^|,^^^^|,%$]]]]`