中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-29 17:36
47,813 topics / 349,918 posts / today 0 new / 48,278 members
DOS批处理 & 脚本技术(批处理室) » Ask: How to judge that the input variable is empty.
Printable Version  4,853 / 19
Floor16 3742668 Posted 2006-12-11 07:02
荣誉版主 Posts 718 Credits 2,013
It is recommended to use the format if defined varName to judge whether a variable is empty, because in many cases, the judgment of if "var" == "" may be wrong due to the variable containing special values.
Floor17 yardian Posted 2006-12-12 01:59
中级用户 Posts 85 Credits 305
The method above can only judge whether the variable exists, but it seems it can't judge whether the variable is empty. I tried:
set B=
if defined B (echo B dump) else (echo full)
The result shows full. Can you explain it in detail?
Floor18 9527 Posted 2006-12-12 02:14
银牌会员 Posts 438 Credits 1,185 From 北京
defined is to determine whether a variable is defined, regardless of its value. The test result of the upstairs was originally correct.

@echo off&setlocal
set b=hello
set b
if defined b (echo YES) else (echo NO)
pause
set b=
set b
if defined b (echo YES) else (echo NO)
pause
Floor19 ccwan Posted 2006-12-12 02:16
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
So it turns out that Brother 9527 has joined KFC! ^_^
Floor20 yardian Posted 2006-12-12 02:23
中级用户 Posts 85 Credits 305
Originally posted by 9527 at 2006-12-12 02:14 AM:
defined is to determine whether a variable is defined, regardless of what value it has. The test result of the upstairs is originally correct
@echo off&setlocal
set b=hello
set b
if defined b (echo YES) else (echo NO)
p ...



Mistakenly reversed the echo.
Prev  1 2
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023