batch-fileecho

How to echo an environment variable of which string value has an '&' in Windows batch?


A batch file has the lines:

set hi=Hello^&World!
echo %hi%

It prints Hello and next outputs the error message:

'World!' is not recognized as an internal or external command,
operable program or batch file.

I want that it prints Hello&World!.

How to do this?


Solution

  • This works for me:

    set "hi=Hello^&World!"
    echo %hi%
    

    Outputs

    Hello&World!