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

时间:2018-06-04 14:48:57

标签: windows batch-file

这是我的test.bat

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

当我在Windows 10上运行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 . . .

我无法弄明白。我检查了我的PATH,安装了cygwin,查看了几个Stackoverflow帖子,似乎无法使脚本正常工作。该脚本创建为一个简单的测试,仅此而已。

1 个答案:

答案 0 :(得分:0)

根据我的评论,这是Windows的批处理文件(它通常有.cmd扩展名,但可能会使用.bat

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