![]() |
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-08-13 03:19 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS学习入门 & 精彩文章 (教学室) » A batch file question? Thanks |
| Printable Version 627 / 2 |
| Floor1 sizzling | Posted 2003-12-09 00:00 |
| 初级用户 Posts 6 Credits 130 | |
|
I have a question:
About SETRAMD.BAT in the Win98 boot disk: :loop if errorlevel %1 goto no_shift :do_shift set cdrom=%2 shift shift if not %1*==* goto loop goto no_ramdrive :no_shift set ramd=%2 How should the line %1*==* here be understood? Why is there also a * after %1? Thanks |
|
| Floor2 willsort | Posted 2003-12-10 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re sizzling:
This is a defensive trick used to avoid a syntax error when a parameter is empty. In the example above, if the IF line were changed to if not %1== goto loop it would not conform to the syntax rules, because DOS's command interpreter requires a non-empty string parameter immediately on both sides of ==. In other words, in batch processing there is no concept of an empty string, so we need to make some compromise: if not %1*==* goto loop This way, when %1 is empty, the above line is replaced with if not *==* goto loop the condition is true and the jump is executed; otherwise it is false, and execution continues with the next statement. Also, * is not the only character that can be used for defensive design. It can be replaced completely with any other character or string, as long as both sides of == remain consistent. Many programmers used to high-level languages are accustomed to the following format: if not ''%1''=='''' goto loop or if not "%1"=="" goto loop |
|
| Floor3 sizzling | Posted 2003-12-10 00:00 |
| 初级用户 Posts 6 Credits 130 | |
|
Thanks to willsor t for the guidance!
Now I finally understand it. Mainly because I overlooked the case when %1 is empty! Haha |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |