1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

@replace weirdness

Discussion in 'Support' started by jabelli, Jan 17, 2013.

  1. jabelli

    Joined:
    Oct 29, 2008
    Messages:
    83
    Likes Received:
    0
    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[^^|,^^^^|,%$]]]]`
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4

Share This Page