How can a batch script do the equivalent of “cat << eof”?

后端 未结 2 1326
醉酒成梦
醉酒成梦 2020-12-29 17:49

In Linux (Bash) there is a very useful functionality for dumping literal text out to another file like this:

cat > see.txt << EOF
contents going int         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 18:25

    In your code is missing a single endlocal in your FOR-loop.
    You create for each loop a new local-context through the setlocal EnableDelayedExpansion, this will explode with some more lines in your text file.

    And to preserve the exclamation marks (and also the carets) you need the toggling technic DOS batch files: How to read a file?

    setlocal DisableDelayedExpansion
    for /f "usebackq skip=%startLine% delims=" %%a in (`"findstr /n ^^ %~dpnx0"`) do (
        set "oneLine=%%a"
        setlocal EnableDelayedExpansion
        set "oneLine=!oneLine:*:=!"
        set /a linesLeftToRead-=1
        if !linesLeftToRead! LEQ 0 exit /B
        echo(!oneLine!>>%outFile%
        **endlocal**
    )
    

提交回复
热议问题