简体   繁体   中英

write file with setlocal enableDelayedExpansion error

I want a script to write a file with this output:

rem ===[A]==========[B]==========[C] # =========[D]==========[E]==========[F] # =========[G]==========[H]==========[I] 
set "A1= " & set "B1= " & set "C1= " # & set "D1= " & set "E1= " & set "F1= " # & set "G1= " & set "H1=5" & set "I1= "

In this case i want to use EnableDelayedExpansion
I wrote this script:

setlocal EnableDelayedExpansion
set file="test.bat"
echo rem ===[A]==========[B]==========[C] # =========[D]==========[E]==========[F] # =========[G]==========[H]==========[I] >> %file%
echo set "A1= " ^^& set "B1= " ^^& set "C1= " # ^^& set "D1= " ^^& set "E1= " ^^& set "F1= " # ^^& set "G1= " ^^& set "H1=5" ^^& set "I1= " >> %file%

But the output is only one line:

rem ===[A]==========[B]==========[C] # =========[D]==========[E]==========[F] # =========[G]==========[H]==========[I]

How can i make the output like what i want with EnableDelayedExpansion ?

Use one single ^ rather than two when escaping special characters. Change the last line in your script to:

echo set "A1= " ^& set "B1= " ^& set "C1= " # ^& set "D1= " ^& set "E1= " ^& set "F1= " # ^& set "G1= " ^& set "H1=5" ^& set "I1= " >> %file%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM