![]() |
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-09-15 12:31 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » Some doubts about the set command (solved) |
| Printable Version 9,831 / 44 |
| Floor1 hangyug | Posted 2007-01-21 00:38 |
| 初级用户 Posts 43 Credits 99 | |
|
Learning batch processing, I learned the set command and was completely confused. I searched in the forum and there are some set-related ones, but after reading them, I still don't understand. I also read the built-in help, but I still don't get it. Does anyone have a better tutorial on set? You can also send a link. Thanks in advance.
[ Last edited by namejm on 2007-1-20 at 08:07 PM ] |
|
| Floor2 ccwan | Posted 2007-01-21 00:43 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
Wherever not understand, put forward it. There must always be someone who can answer it, right?
|
|
| Floor3 timlee | Posted 2007-01-21 00:48 |
| 新手上路 Posts 8 Credits 16 | |
|
Let's say it so that we can also learn from it.
|
|
| Floor4 hangyug | Posted 2007-01-21 01:16 |
| 初级用户 Posts 43 Credits 99 | |
|
Problem 1:
The first line `set a=` means initializing the variable `a` without giving it an initial value. Then `set/p a=请输入关键字……` is used to let the user input a value and assign it to variable `a`. The statement "The set command does not allow variables to contain equal signs" means that if you try to assign a value to a variable using the set command, the value should not contain the equal sign character. Problem 2: In `set "STARTPRGNAME=%STARTPRGNAME:"=%"`, `"=%"` is used to remove all double quotes from the variable `STARTPRGNAME`. The `/i` in `if /i "%STARTPRGNAME%" == "cmd" goto :cmd_exe` means case - insensitive comparison. The `:.bat` in `if not "%STARTPRGNAME:.bat=%" == "%STARTPRGNAME%" goto :cmd_or_bat` is used to remove the substring `.bat` from the variable `STARTPRGNAME`. The reason for enclosing `set "STARTPRGNAME=%STARTPRGNAME:"=%"` in quotes is to handle cases where the variable value might contain spaces. `%STARTPRGNAME%` is getting the value of the variable `STARTPRGNAME`, and `%1` is the first command - line argument, they are different in terms of their source (one is a variable, the other is a command - line argument). Translated: Problem 1: The questions are all very basic, hope everyone has a little patience... Hehe. Problem one: set a= set/p a=Please enter the keyword... start http://www.baidu.com/s?wd=%a% The built - in help is written like this: SET /P variable= Why is there nothing on the right side of the equal sign in the first line? Then what is assigned to variable a exactly? And there is such a sentence: "The set command does not allow variables to contain equal signs" How to understand it? Problem two: I saw such a post: set "STARTPRGNAME=%STARTPRGNAME:"=%" What does ":=" mean in the statement? if /i "%STARTPRGNAME%" == "cmd" goto :cmd_exe What does /i mean in the statement? if not "%STARTPRGNAME:.bat=%" == "%STARTPRGNAME%" goto :cmd_or_bat What does .bat mean in the statement? In the first sentence: Why is the statement after set enclosed in quotes? What does it represent? Also, what does the %STARTPRGNAME on the right side of the equal sign mean? What is assigned to STARTPRGNAME on the left side of the equal sign? In the second sentence: What is the situation of "%STARTPRGNAME%"? What is the difference between it and %1? |
|
| Floor5 0401 | Posted 2007-01-21 03:13 |
| 中级用户 Posts 88 Credits 435 | |
|
HoHoHo~ I'm more suitable for answering such basic questions.
For question one, just try it yourself. The first sentence originally means to set variable a to empty, so there is naturally nothing on the right side of the equal sign. In fact, it's just deleting variable a. The second sentence means reading the user's input and assigning it to variable a. The sentence "" is a prompt for the user to see. That is, after you execute , the screen displays , and then you enter and press Enter, the value of variable a will be . You can understand it by adding a sentence . The statement that "" is easy to understand. Like the above a is the variable name, can you set a variable named ? For question two: You carefully check the help of and will see this sentence , which means replacing all characters or strings in variable with . The help also says that . For example, if the value of variable is , after executing , the value of variable is . Thus, this sentence can be understood as deleting all quotes in variable and assigning the processed value back to . There are quotes because the character to be processed is a . Continue. . . in means case-insensitive. This is easy to understand, you are too lazy, building owner. The next sentence is the same meaning as the above variable replacement. For example, assume the value of variable is , then ==, which may mean like this (I guess): if it is a.bat file, jump to here . Answer the last line. is to expand the value of variable , in fact, it is to read the variable. is just used to represent , because in batch processing, doubling can get one , and means the first parameter of the batch file. You can try creating a new batch file, such as , the file content is only one line , and then call it with the command line to see . Typing is so tiring~~ [ Last edited by 0401 on 2007-1-21 at 03:18 AM ] |
|
| Floor6 hangyug | Posted 2007-01-21 04:46 |
| 初级用户 Posts 43 Credits 99 | |
|
Thanks to the above - mentioned person for the patient answer, you've worked hard... I understand question one, but you may not have understood my question two.
I'll say it again. The statement "set "STARTPRGNAME=%STARTPRGNAME:"=%"": What does ":=%" mean? The statement "if /i "%STARTPRGNAME%" == "cmd" goto :cmd_exe": What does /i mean? The statement "if not "%STARTPRGNAME:.bat=%" == "%STARTPRGNAME%" goto :cmd_or_bat": What does .bat mean? All of the above are the contents of a post I saw, and the questions are asked by the person who wrote this post, and my questions are below: In the first sentence: Why is the statement after set enclosed in quotes? What does it represent? Also, what does the meaning of %STARTPRGNAME on the right side of the equal sign mean? What is assigned to STARTPRGNAME on the left side of the equal sign? In the second sentence: What's the matter with "%STARTPRGNAME%"? Especially: What's the difference between it ("%STARTPRGNAME%") and %%1? I didn't see the parameter in the form of "%STARTPRGNAME%" when learning if... [ Last edited by hangyug on 2007 - 1 - 20 at 03:50 PM ] |
|
| Floor7 tao0610 | Posted 2007-01-21 05:19 |
| 高级用户 Posts 218 Credits 579 | |
|
Two Great Secrets:
1. Make good use of the search function 2. Read more help information ..... |
|
| Floor8 0401 | Posted 2007-01-21 06:25 |
| 中级用户 Posts 88 Credits 435 | |
|
To the original poster:
I understood your question two in the reply, but you didn't understand my answer. Then I'll say it again. Before saying that, I want to tell you that if you can try it yourself, I think you already know why. My previous answer, I hope you can read it carefully again, I'm just giving an example here. Enough, original poster, read the above explanation several times. I can't express it any simpler. BTW: Thanks to redtek for typing for me and adding points, heh heh. [ Last edited by 0401 on 2007-1-21 at 06:30 AM ] |
|
| Floor9 hangyug | Posted 2007-01-21 08:04 |
| 初级用户 Posts 43 Credits 99 | |
|
Thank you, Brother 0401. It turns out you've answered both my question and the question in the post I cited. Thank you again for your reply...
|
|
| Floor10 kafen | Posted 2007-01-21 09:00 |
| 初级用户 Posts 43 Credits 97 | |
|
I also want to thank such a warm - hearted and patient friend!
|
|
| Floor11 shorterz | Posted 2007-01-23 11:36 |
| 初级用户 Posts 11 Credits 25 | |
|
Learned quite a bit, heh heh, continue...
|
|
| Floor12 g4rr | Posted 2007-01-24 05:28 |
| 初级用户 Posts 32 Credits 68 From 广东潮州 | |
|
It is suggested that if you look at several more examples, you will find it very easy to understand.
Also, you need to pay attention that the current selection command is different from the old DOS ones. |
|
| Floor13 sjjhhx | Posted 2007-02-08 09:55 |
| 初级用户 Posts 11 Credits 24 | |
|
It's explained very detailedly, so that we newcomers can understand. Thanks to brother 0401 for his patience and meticulousness!
|
|
| Floor14 anqing | Posted 2007-02-08 11:18 |
| 高级用户 Posts 413 Credits 859 | |
|
The explanation about set is very detailed in the 5th floor, and there are examples. A bit better looking
|
|
| Floor15 juventusryp | Posted 2007-02-14 06:09 |
| 初级用户 Posts 40 Credits 88 | |
|
What the person on the 5th floor said is very clear. We beginners can understand it at a glance
|
|
| 1 2 3 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |