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-08-11 07:44
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask the expert to explain the symbols < and the command IF NOT defined! View 1,556 Replies 6
Original Poster Posted 2007-09-23 16:05 ·  中国 山西 太原 电信
初级用户
Credits 56
Posts 22
Joined 2006-12-13 10:54
19-year member
UID 73399
Gender Male
Status Offline
As the title. Hope experts can inform in the way of examples, and I am very grateful!
Floor 2 Posted 2007-09-23 18:00 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
Floor 3 Posted 2007-09-23 21:33 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
< represents input redirection
IF NOT defined means "if not defined"

C:\>set a=1

C:\>if not defined a (echo yes) else (echo no)
no
Floor 4 Posted 2007-12-21 12:39 ·  中国 安徽 马鞍山 电信
中级用户
★★
拟谷盗
Credits 312
Posts 108
Joined 2007-01-21 11:36
19-year member
UID 77238
Gender Male
Status Offline
Using `if not defined` can delete duplicate lines
for /f "delims=" %%i in (test.txt) do (
if not defined %%i set %%i=A & echo %%i>>test2.txt)
Floor 5 Posted 2007-12-22 11:01 ·  中国 广东 广州 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Originally posted by fbwolf at 2007-9-23 04:05 PM:
As the title suggests
I hope that the experts will inform me in an example way, and I am very grateful!





C:\>echo abcd>a.txt

C:\>set /p test=<a.txt

C:\>echo %test%
abcd

C:\>




C:\>set test=a

C:\>if defined test (echo Variable test exists) else (echo Variable test does not exist)
Variable test exists

C:\>if not defined test (echo Variable test does not exist) else (echo Variable test exists)
Variable test exists

C:\>set test=

C:\>if defined tset (echo Variable test exists) else (echo Variable test does not exist)
Variable test does not exist

C:\>if not defined tset (echo Variable test does not exist) else (echo Variable test exists)
Variable test does not exist

C:\>
Floor 6 Posted 2007-12-26 16:22 ·  中国 北京 华为云
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
Finally understand some, thank you very much for the 5th floor!
Floor 7 Posted 2009-02-07 20:31 ·  中国 北京 联通
中级用户
★★
Credits 313
Posts 162
Joined 2007-04-02 06:45
19-year member
UID 83693
Gender Male
Status Offline
Using `if not defined` can delete duplicate lines
for /f "delims=" %%i in (test.txt) do (
if not defined %%i set %%i=A && echo %%i>>test2.txt)

In the line `if not defined %%i set %%i=A & echo %%i>>test2.txt)`, the `&` should be `&&`.
Forum Jump: