代码之家  ›  专栏  ›  技术社区  ›  Josh

无法正确运行.bat文件(Windows 10)

  •  -1
  • Josh  · 技术社区  · 7 年前

    这是我的 test.bat

    #!/bin/bash
    #set the STRING variable
    SET STRING=Hello World
    #Print the contents of the variable to the screen
    echo $STRING
    pause
    

    当我在Windows10上运行test.bat时,会得到以下输出:

    C:\Workspace\mcc-batch-jobs>#!/bin/bash
    '#!' is not recognized as an internal or external command,
    operable program or batch file.
    
    C:\Workspace\mcc-batch-jobs>#set the STRING variable
    '#set' is not recognized as an internal or external command,
    operable program or batch file.
    
    C:\Workspace\mcc-batch-jobs>SET STRING=Hello World
    
    C:\Workspace\mcc-batch-jobs>#Print the contents of the variable to the screen
    '#Print' is not recognized as an internal or external command,
    operable program or batch file.
    
    C:\Workspace\mcc-batch-jobs>echo $STRING
    $STRING
    
    C:\Workspace\mcc-batch-jobs>pause
    Press any key to continue . . .
    

    我想不出来。我检查了我的路径,安装了cygwin,查看了几个stackoverflow帖子,似乎无法让脚本工作。脚本是作为一个简单的测试而创建的。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Compo    7 年前

    从我的评论来看,这是一个windows的批处理文件, (它通常有一个 .cmd 扩展,但可以使用 .bat 相反) :

    @ECHO Off
    SET "STRING=Hello World"
    REM Print the contents of the variable to the screen
    ECHO %STRING%
    PAUSE