I am trying to create a couple of files using a batch script. Basically, For all my projects and team members these two files are essential. Hence I created a batch script so when a member runs the batch script in a project folder, the required files are created.

In one of the file there is a line like the following

a.configure("3") do |config| 

and

# config.vm.provider :vbx do |vb|

I wanted these lines to printed exactly as it is to a file.

my batch file simply does a echo of these two lines.

But I get an error saying "do was unexpected at this time."

I am suspecting that something in those lines is a batch command or variable which is getting interpolated. I have never used batch scripting.

if exist file1 del file1 (
    echo. a.configure("3") do |config|
    echo. # config.vm.provider :vbx do |vb|
    echo. # Cannot be accessed by any external networks.
) >file1 
有帮助吗?

解决方案

rem This should not fail. Just escaped pipes

break>file.txt
>>file.txt  echo a.configure("3") do ^|config^| 
>>file.txt  echo # config.vm.provider :vbx do ^|vb^|
>>file.txt  echo ------------------------------------

rem But inside a block, the closing parenthesis needs to be scaped
rem to not be interpreted as the closing parenthesis of the block

if 1==1 (
    >>file.txt  echo a.configure("3"^) do ^|config^| 
    >>file.txt  echo # config.vm.provider :vbx do ^|vb^|
    >>file.txt  echo ------------------------------------
) 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top