Skip navigation

Q. How can I write a long command, over multiple lines, in either the command prompt window or a batch file?

Writing multiple line scripts? This line continuation character can help.

A. The Windows command prompt (cmd.exe) allows the ^ (Shift + 6) character to be used to indicate line continuation. It can be used both from the normal command prompt (which will actually prompt the user for more input if used) and within a batch file.

Below is an example of the character used in a command prompt (although it could easily have fit on one line):

 

D:\Temp>copy ^
        

 

More?a.a ^

 

More?b.b

1 file(s) copied.

I could place the same content in a batch file, and interestingly, when it’s run, it automatically puts the multiple lines onto a single line. For example, if my batch file contains the following:

 

copy ^
a.a ^
b.b

when I run it, I see the following on screen, which shows the command on one line:

 

<>D:\Temp>@badcopy.bat
        

 

D:\Temp>copy a.a b.b

1 file(s) copied.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish