How to split double quoted line into multiple lines in Windows batch file?

后端 未结 5 1649

Long commands in Windows batch files can be split to multiple lines by using the ^ as mentioned in Long commands split over multiple lines in Windows Vista batc

5条回答
  •  盖世英雄少女心
    2020-11-30 04:24

    The most straight forward answer is to escape the quotes. They will be printed, but they will not functionally quote the contents as far as CMD.EXE is concerned.

    @echo off
    echo ^"A very long line I want to ^
    split into two lines^"
    

    Any special characters that appear in the line must also be escaped since they are no longer functionally quoted.

    @echo off
    echo ^"A very long line I want to ^
    split into two lines ^
    that also contains special characters ^^ ^& ^| ^> ^< ^"
    

    As jeb said, the line continuation escapes the first character of the next line. So if the first character of the next line happens to be a special character, it should not be escaped a second time. The code below will give the exact same results as the previous example.

    @echo off
    echo ^"A very long line I want to ^
    split into two lines ^
    that also contains special characters ^^ ^
    & ^| ^> ^< ^"
    

提交回复
热议问题