美文网首页
Windows Batch判断变量是否定义

Windows Batch判断变量是否定义

作者: CodingCode | 来源:发表于2023-12-19 01:56 被阅读0次
@echo off

if defined MYVAR (
   echo ERROR: MYVAR is defined
) else (
   echo ERROR: MYVAR is not defined
)

if not defined MYVAR (
   echo MYVAR is not defined
) else (
   echo MYVAR is defined
)

运行:

C:\> set MYVAR=<avalue>
C:\> test.bat
MYVAR is defined
MYVAR is defined

C:\> set MYVAR=
C:\> test.bat
MYVAR is defined
MYVAR is defined

相关文章

网友评论

      本文标题:Windows Batch判断变量是否定义

      本文链接:https://www.haomeiwen.com/subject/ohkzgdtx.html