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 06:54
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] A batch file in ghost8? I don't understand! View 1,455 Replies 4
Original Poster Posted 2004-11-12 00:00 ·  中国 广西 柳州 电信
初级用户
Credits 168
Posts 27
Joined 2004-11-03 00:00
21-year member
UID 33247
Gender Male
Status Offline
The code you provided is a batch script related to network configuration and Ghost operations.

For the line `if not "%windir%*"=="*" goto Error`, it's checking if `%windir%` (which is the path to the Windows directory) concatenated with an asterisk is equal to an asterisk alone. Effectively, it's a way to check if `%windir%` is not an empty string. Because if `%windir%` is set (i.e., we're in Windows), then `%windir%*` will be something like `C:\Windows*` which is not equal to `*`, so it will not go to the `Error` label. If `%windir%` is empty (i.e., we're in DOS), then `%windir%*` is just `*`, so it will go to the `Error` label.

For the line `if "%3*"=="*" goto Sample`, it's checking if the third command-line argument (`%3`) concatenated with an asterisk is equal to an asterisk alone. This is a way to check if the third command-line argument is empty. If the third argument is empty, then it will go to the `Sample` label.

So, in summary:

The `*` is used as a way to concatenate with the variable value to perform a check for the presence or absence of the variable's value. The first check is to see if we're in Windows (by checking if `%windir%` is set), and the second check is to see if the third command-line argument is provided.
Floor 2 Posted 2004-11-12 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
In fact, the * here is redundant. When using if to judge whether an environment variable is an empty string, in order to prevent the environment variable from being empty and causing "if %var%==1" to appear as "if ==1", generally, one or more characters are added around the variable to prevent it. The most common way is to enclose the environment variable in double quotes, for example, if "%windir%"==""". Of course, you can also use if %windir%#==# or if %windir%*==* instead of double quotes.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2004-11-16 00:00 ·  中国 广西 柳州 电信
初级用户
Credits 168
Posts 27
Joined 2004-11-03 00:00
21-year member
UID 33247
Gender Male
Status Offline
Heheh, thanks,大侠climbing! It turns out that `if not "%windir%*"=="*"` is to prevent `%windir%` from being empty, leading to a situation where `if not ==*` occurs
Floor 4 Posted 2004-11-29 00:00 ·  中国 上海 杨浦区 电信
初级用户
Credits 126
Posts 11
Joined 2004-09-30 00:00
21-year member
UID 31977
Gender Male
Status Offline
Floor 5 Posted 2006-10-14 00:44 ·  中国 广东 东莞 电信
中级用户
★★
Credits 282
Posts 130
Joined 2006-09-20 22:25
19-year member
UID 63201
From 广东
Status Offline
Learning
~~~~好好学习
天天向上~~~~
Forum Jump: