BAT脚本常见结构-if else

系统+安全 Liemer_Lius 934℃ 0评论

代码示例:

@echo off
set string1="Hello Lius..."
set string2="Hello Liemer..."
if %string1%==%string2% (echo Yes...) else (echo No...)
if /i %string1% lss %string2% (echo string1 ^< string2) else (echo string1 ^>= string2)
set /p choice=Do you want to show datetime? (y/n)
if /i not %choice% EQU n echo The datetime is: %date% %time%
pause

格式:
if [/i] [not] string1 compare-op string2 command1 [commond2]…
if [/i] [not] string1 compare-op string2 (command1 [commond2]…) else (command3 [commond4]…)
/i: 不区分大小写
not: 表示否定
compare-op有以下几种类型;
等于:==, equ
不等于:neq
小于:lss
小于等于:leq
大于:gtr
大于等于:geq
设定变量时候的提示:set /p

 

 

 

转载请注明:liutianfeng.com » BAT脚本常见结构-if else

喜欢 (0)

发表回复