How to echo “2” (no quotes) to a file, from a batch script?

后端 未结 11 1356
孤街浪徒
孤街浪徒 2020-12-02 22:13

How do I echo the number 2 into a file, from a batch script?

This doesn\'t work:

Echo 2>> file.txt

because 2&g

相关标签:
11条回答
  • 2020-12-02 22:26

    Or you can use the delayed expansion

    setlocal EnableDelayedExpansion
    set "var=2"
    echo(!var!>> file.txt
    
    0 讨论(0)
  • 2020-12-02 22:39

    Based on this answer, if anyone is wondering how to do this:

    echo "command1 && command2" > file.txt
    

    with no qoutes in file.txt then you do it like this:

    echo command1 ^&^& command2 > file.txt
    

    Tested on Windows Server 2003.

    0 讨论(0)
  • 2020-12-02 22:40

    Little-known feature: The redirection operator can go anywhere on the line.

    >>file.txt echo 2
    
    0 讨论(0)
  • 2020-12-02 22:43

    Use the ^ escape :

    Echo ^2>> file.txt
    
    0 讨论(0)
  • 2020-12-02 22:45

    another method

    echo>>file.txt 2
    
    0 讨论(0)
提交回复
热议问题