0

What I mean is this:

Echo testing >> new_text_document.txt

Is there a way to give "testing" multiple lines?

Might it work better with variables like:

Set xyz= testing Echo %testing% >> new_text_document.txt

I don't know. If you can help, it would be apreaciated. Thanks in advance.

4

1 回答 1

1

There are many ways, it really depends on what you need. One way is to put newline in a variable (note the 2 empty lines are critical):

@echo off
setlocal EnableDelayedExpansion
set NL=^


echo two!NL!lines >> new_text_document.txt

Use one or two > does not matter. since >> appends you can do many lines of echo too

@echo off
:other stuff
echo multiple  >> new_text_document.txt
echo lines  >> new_text_document.txt
echo.  >> new_text_document.txt
echo of text  >> new_text_document.txt

that may be clunky so you could do something like this instead

@echo off
:other stuff
(
  echo multiple 
  echo lines 
  echo.  
  echo of text  
) >> new_text_document.txt

Last but not least you can do something similar to the bash trick but you will have no EOL marker.

@echo off
more +4 %~f0 >> new_text_document.txt
exit /b

your 
multi
line 
text

In addition to this its possible to for loop the file yourself this way you can have a EOL marker for many different pieces.

于 2013-07-22T06:32:27.177 回答