China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-20 19:13
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask: How to judge that the input variable is empty. View 4,234 Replies 19
Floor 16 Posted 2006-12-11 07:02 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
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.
Floor 17 Posted 2006-12-12 01:59 ·  中国 浙江 杭州 电信
中级用户
★★
Credits 305
Posts 85
Joined 2005-05-23 00:00
21-year member
UID 39004
Gender Male
Status Offline
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?
Floor 18 Posted 2006-12-12 02:14 ·  中国 北京 联通
银牌会员
★★★
努力做坏人
Credits 1,185
Posts 438
Joined 2006-08-28 12:00
19-year member
UID 61449
From 北京
Status Offline
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
我今后在论坛的目标就是做个超级坏人!!!
Floor 19 Posted 2006-12-12 02:16 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
So it turns out that Brother 9527 has joined KFC! ^_^
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 20 Posted 2006-12-12 02:23 ·  中国 浙江 杭州 电信
中级用户
★★
Credits 305
Posts 85
Joined 2005-05-23 00:00
21-year member
UID 39004
Gender Male
Status Offline
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.
Forum Jump: