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-02 22:26
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question about uppercase/lowercase conversion??? View 1,428 Replies 6
Original Poster Posted 2006-12-19 05:14 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
The system is 2k
set /p con="Continue (Y/N):"

set con=%con:y=Y%
set con=%con:n=N%

if %con%==Y goto continue
if %con%==N goto out
Written in a cmd script, while the program is running, echo %con%
I found that con at this point is y=Y
That is to say, con is now equal to the expression y=Y
Then when if does the check it becomes if y=Y==Y goto continue
But this line gives a syntax error in 2003, and I don't know why
Also, after executing set con=%con:y=Y% at the command line
echo %con% at this point con is equal to Y
Why does the command behave differently at the command line and in a script?
Floor 2 Posted 2006-12-19 12:17 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline

IF /I == ……



The if /i parameter can judge without distinguishing uppercase or lowercase~:)
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 3 Posted 2006-12-19 22:22 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
Then this line set con=%con:y=Y%
when written in a cmd script
why does con become y=Y? I don't understand
Floor 4 Posted 2006-12-19 22:43 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
Also in 2003
if /i %con%==Y goto continue
it still gives an error
Floor 5 Posted 2006-12-19 23:24 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
To prevent conflicts caused by empty variables or unexpected symbols, you must


IF /I ==


You must wrap the variable being compared with some kind of symbol, like the " " square brackets above, so that if can read it clearly and cleanly. With well-structured code, the chance of errors is smaller~:)

The if /i parameter already ignores case, so there is no need to write the line set con=%con:y=Y% anymore~:)


If you don't like using the equals sign for comparison, then if also provides the following forms:



EQU - equal to
NEQ - not equal to
LSS - less than
LEQ - less than or equal to
GTR - greater than
GEQ - greater than or equal to


[ Last edited by redtek on 2006-12-19 at 10:25 AM ]
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 6 Posted 2006-12-19 23:30 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 141
Posts 60
Joined 2006-10-28 05:54
19-year member
UID 68605
Gender Male
From 天津
Status Offline
Got it, thanks redtek
Floor 7 Posted 2006-12-20 00:50 ·  中国 广东 深圳 福田区 电信
初级用户
Credits 32
Posts 16
Joined 2006-10-19 21:11
19-year member
UID 66985
Gender Male
Status Offline
Not bad, learned something.
Forum Jump: