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-06-30 05:58
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Please ask your specific question about the set delay variable so that I can provide the corresponding translation and relevant content. View 6,573 Replies 25
Floor 16 Posted 2006-11-15 21:41 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
The reason for not understanding is: Trying to start reading from a command string mixed with (variable assignment, variable content replacement, variable display, how to display special symbols) and so on from the beginning :)

) Variable assignment: set str=www.cn-dos.net

) Variable content replacement: %str:www=bbs%

) Variable display: echo Execute set str=%%str:www=bbs%%
(%% represents displaying the % sign itself)

) Displaying special symbols: echo Execute set str=%%str:www=bbs%%
%% double percent signs represent displaying % itself (irrelevant to the value and processing), and the display result is: Execute set str=%str:www=bbs%

) ……

The following code is very simple (the reason it is called simple is: If you have learned all the basic knowledge, it is very simple)
The following code is also relatively difficult (the reason it is called relatively difficult is: If you don't look at the basic knowledge and start reading it like a program, there will always be things you don't understand)

@echo off
set str=www.cn-dos.net
echo The content of variable str before replacement is: %str%
echo Execute set str=%%str:www=bbs%%
echo The content of variable str after replacement is: %str:www=bbs%
pause



It is suggested that brothers dshh98 and xue2ye start learning from the basic knowledge first, and you will become more and more handy ~:)

Batch processing is different from the learning points of C language or VB:
-----------------------------------
) C and VB, etc., all have function libraries (functions) that can be called. Whether it is file operation or string extraction, printing, etc., there are special function libraries to choose from.

) While batch processing is a collection of commands. Whether it is a DOS command or the Windows CMD Shell or calling system or third-party provided applications, etc....

The reason it is called "batch processing" is that you uniformly use the "batch processing" method to run those commands and assignment operations that you want to call and run ~:)

) "Batch processing" does not provide you with a way to call APIs or function libraries. The system (DOS or Windows) provides you with internal, external commands or applications, and you can call whatever is available.

For example: DIR is an internal command of the system, but DIR has many parameters... (it is not provided by batch processing)

According to personal understanding, an unofficial and non-standard explanation is: Batch processing is a collection of commands, which means putting many commands or programs in a script-written file and running them uniformly.

) So, the learning points of C or VB are grammar, function libraries, APIs...

) Learning points of batch processing: How deep you understand the internal commands or external commands provided by the operating system or third-party applications, and how deep you can use them.

(For example:) REG.EXE (CMD Shell), which operates on the registry.
REG has many execution parameters that can be selected. Batch processing applies it just by calling one of its parameters,
and putting it in the batch processing to be run together with other instructions.

(For example:) Format the command, which also has many parameters. It can be run directly or called to execute in this batch processing script file.

So, to use batch processing smoothly (for example: like the version master who can do whatever he wants to do),
you must thoroughly learn the basic knowledge such as variable assignment, variable content replacement, special symbols, escape (escape characters), etc. ~:)

And how deep you have learned these basic knowledge and how thoroughly you understand them means how smoothly you can complete your will ~:)

) If you study it like programming (like modern teaching methods: high-speed something like 24-hour quick success, something like from entry to proficiency learning methods), it simply won't work ~:)
In the end, you have to come back and learn these basic knowledge again ~:)

) It is suggested to start learning from the basics. (Batch processing depends on these basics, and you can't get anywhere without these basics)


==========================================

(An example is given)

"How to judge the length of a variable?"

If you use batch processing to calculate the length of the string contained in a variable (a variable that stores a string),
the system does not directly provide a function like C or VB to calculate the length of a string,
at this time, the algorithm and a large amount of experience in processing variables accumulated on weekdays tell you:
You should use different methods such as looping through individual variables and cumulative counting to cleverly achieve the above function ~:)

(The detailed example can be found at the following address:)
http://www.cn-dos.net/forum/viewthread.php?tid=24745&fpage=1

And these are not difficult. It still applies the basic knowledge such as variable assignment, looping, accumulation (also variable assignment), delayed variables...
So, you can't get anywhere without the basic knowledge ~:)

--------------------------------
Therefore, not starting to learn from the basic knowledge when learning batch processing is equal to learning in vain ~:)

[ Last edited by redtek on 2006-11-15 at 09:57 PM ]
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 17 Posted 2006-11-16 08:06 ·  中国 浙江 温州 瑞安市 电信
初级用户
Credits 26
Posts 11
Joined 2006-11-11 06:25
19-year member
UID 70205
Gender Male
Status Offline
Really thank you all great guys, I finally learned it. Hehe. I used to play with bat too, but generally only did some basic things. Not many things could be achieved. Now I can finally improve. Thanks. cn-dos. Thanks everyone.
Floor 18 Posted 2006-11-16 10:50 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
set str=%str:www=bbs% Replace "www.cn-dos.net" with "bbs.cn-dos.net"
Floor 19 Posted 2007-01-13 10:58 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
Got to know a little more. Solved my problem.
Floor 20 Posted 2007-01-19 05:06 ·  中国 北京 鹏博士BGP
新手上路
Credits 1
Posts 3
Joined 2007-01-17 09:26
19-year member
UID 76788
Gender Male
Status Offline
Floor 21 Posted 2007-03-17 21:53 ·  中国 上海 黄浦区 电信
初级用户
Credits 49
Posts 22
Joined 2005-08-04 13:44
20-year member
UID 41332
Gender Male
Status Offline
Floor 22 Posted 2007-03-18 00:32 ·  中国 上海 黄浦区 电信
初级用户
Credits 49
Posts 22
Joined 2005-08-04 13:44
20-year member
UID 41332
Gender Male
Status Offline
Floor 23 Posted 2007-03-18 04:50 ·  中国 陕西 咸阳 电信
新手上路
Credits 10
Posts 5
Joined 2007-03-18 04:23
19-year member
UID 82118
Gender Male
Status Offline
Thank you for the poster's share
Floor 24 Posted 2007-12-23 20:39 ·  中国 广西 百色 中移铁通
银牌会员
★★★
永远的菜鸟
Credits 1,335
Posts 574
Joined 2007-11-27 12:50
18-year member
UID 103929
Gender Male
From 广西
Status Offline
Very detailed and specific, thank you very much!
Floor 25 Posted 2008-01-11 15:00 ·  中国 北京 联通
新手上路
Credits 10
Posts 5
Joined 2007-12-27 11:33
18-year member
UID 106916
Gender Male
Status Offline
redtek
So patient! A role model~!
Floor 26 Posted 2008-08-20 20:46 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 133
Posts 75
Joined 2008-08-03 01:08
17-year member
UID 122677
Gender Male
Status Offline
Forum Jump: