2

I have to execute a batch file by the CALL statement and pass a parameter to that. Everything works fine until I need use the ^ sign.

I'm running XP and the problem can be reproduced by two simple commands:

Without CALL

c:\>echo password: "secret(<^>)secret"
password: "secret(<^>)secret"

With CALL

c:\>call echo password: "secret(<^>)secret"
password: "secret(<^^>)secret"

How can I avoid to don't duplicate the ^ sign when using CALL?

koszti
  • 131
  • 8

1 Answers1

2

In this way you can't avoid it, as CALL will always double all carets just before the line is reparsed the second time.

If you really need to use a CALL you should put your data in a variable and expand this after the CALL-caret-doubling

set "myVar=secret(<^>)secret"
set myVar
call echo Password "%%myVar%%"

But even then you got problems, if your secret contains quotes, or if you try to use the variable without quotes.

Therefore you should better use delayed expansion here.
This will also work (without a CALL) inside of brackets.

setlocal EnableDelayedExpansion
(
    set "myVar=secret(<^>)secret"
    echo !myVar!
)

And if your are interested where the double carets come from you could read
How does CMD.EXE parse scripts

Community
  • 1
  • 1
jeb
  • 70,992
  • 15
  • 159
  • 202