Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file if语句中批处理文件中的点的用途是什么?_Batch File - Fatal编程技术网

Batch file if语句中批处理文件中的点的用途是什么?

Batch file if语句中批处理文件中的点的用途是什么?,batch-file,Batch File,点在下面的比较中做了什么?在%1和ABCD之后,与%SOME\u VAR%在同一行 :begin if not %1.==ABCD. goto no_abcd some other code... :no_abcd code related to ABCD .... if NOT %SOME_VAR%.==. goto begin 代码中的圆点保证您正在比较某个东西。因为将nothing与批处理文件中的内容进行比较会导致错误 考虑以下代码: if exist "c:\testfile.txt"

点在下面的比较中做了什么?在%1和ABCD之后,与%SOME\u VAR%在同一行

:begin
if not %1.==ABCD. goto no_abcd
some other code...
:no_abcd
code related to ABCD
....
if NOT %SOME_VAR%.==. goto begin

代码中的圆点保证您正在比较某个东西。因为将nothing与批处理文件中的内容进行比较会导致错误

考虑以下代码:

if exist "c:\testfile.txt" set "FileExists=YES"
if %FileExists%==Yes echo We're all very happy
如果文件不存在会发生什么?将不定义变量FileExists。因此,在该场景中,第二条if语句变成:

if  ==Yes echo We're all very happy
这将产生一个错误。我通常看到使用双引号而不是像这样的点:

if exist "c:\testfile.txt" set "FileExists=YES"
if "%FileExists%"=="Yes" echo We're all very happy
但基本上,任何确保对比双方都有意义的东西。上述代码也可以通过确保始终定义变量来工作:

set "FileExists=NO"
if exist "c:\testfile.txt" set "FileExists=YES"
if %FileExists%==Yes echo We're all very happy
由于代码现在保证变量FileExists在本例中始终是NO或YES,因此我们不需要双引号或其他任何东西

原始代码可能是:

:begin
if not "%~1"=="ABCD" goto no_abcd
some other code...
:no_abcd
code related to ABCD
....
if NOT "%SOME_VAR%"=="" goto begin

它被用作一种糟糕的字符串检查方法,并且没有特定的用途。我建议您将其更改为,If Not%~1==bao GoTo no\u bao,或者如果您想检查第一个参数是否为bao,或者如果/I Not%~1==bao GoTo no\u bao,则将其更改为。第二个类似的应该是,如果定义了某个_VAR GoTo begin