Do Batch files support multiline variables

前端 未结 9 1957
南旧
南旧 2020-12-25 12:54

If so How?

Yes, batch files are lame, but I cannot use powershell, and I don\'t feel like writing a real app to do this simple task....

edit

9条回答
  •  北海茫月
    2020-12-25 13:26

    If you wanted to build something instead, not just outputting, hope this would be useful to you too.


    Firstly, you should make a file. Such as .txt. I'm going to use var.txt as an example.

    Secondly, type in the multi-lines of variables.

    Thirdly, here are the codes, but only works for batch:

    @echo off
    set num=0
    set /p this%num%=<"var.txt"
    goto there
    
    :there
    set /a num=num+1
    for /f "skip=%num%" %%a in (var.txt) do (set this%num% =%%a
    goto there)
    set num=0
    goto build
    
    :build
    rem Example of using multi-lines of variable.
    call echo %%this%num% %%
    set /a num=num+1
    for /f "skip=%num% delims=" %%a in (var.txt) do (call echo %%this%num% %%
    goto build)
    rem Just replace the commands with `echo` part into something else which suits your situation.
    pause >nul
    exit
    

    I admit that strictly speaking, this is not a variable of multi-line, but in my opinion, this is better than nothing.

    You may ask why not just use the setlocal EnableDelayedExpansion command. The reason is simply, that command does work for me (IDK why). Therefore, I thought and made these codes that make the same effect.

提交回复
热议问题