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!
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.
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?
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 ...