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-07-23 06:06
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Solved] About the delay in variable substitution of "set & echo" View 5,871 Replies 21
Original Poster Posted 2005-12-01 20:27 ·  中国 福建 漳州 电信
中级用户
★★
带走
Credits 435
Posts 88
Joined 2005-09-24 19:22
20-year member
UID 42793
Status Offline
Environment: XP Below is the result when I run
C:\>set t=abc & echo %t%
%t%

C:\>set t=abc & echo %t%
abc
The first time I ran it, the value of the variable was not displayed. I tried to write the two sentences separately and save them as a bat file, and I could get the result normally. But I don't know why the one connected by & can't get the expected result, so that when I run Brother Wunaikai's signature, I get such a result.
C:\>%ComSpec% /cset,=^G何奈无── 。何奈可无是原,事奈无做人奈无^G&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
%,:~22,1% %,:~21,1% %,:~20,1% %,:~19,1% %,:~18,1% %,:~17,1% %,:~16,1% %,:~15,1%
%,:~14,1% %,:~13,1% %,:~12,1% %,:~11,1% %,:~10,1% %,:~9,1% %,:~8,1% %,:~7,1% %,
:~6,1% %,:~5,1% %,:~4,1% %,:~3,1% %,:~2,1% %,:~1,1% %,:~0,1%
Is there any solution?
Also, there is one point I don't understand above, why does he use call?
[ Last edited by 0401 on 2005-12-2 at 09:29 ]
Floor 2 Posted 2005-12-01 22:33 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re 0401:

The signature of Wunaike has clearly indicated that this long code is used in the Start Run, not in the command line environment. In the command line, you need to remove the leading %comspec% /c and only keep the content from set,= onwards.

As for set & echo, it originates from a delayed effect of variable substitution. That is to say, the variable set in one statement can be correctly referenced in the next statement. The existence of this delayed effect is due to the shared problem of the command line environment space, which is relatively complicated to talk about in detail. You can refer to cmd /? for relevant instructions.

And the for in the signature actually calls and executes the same statement multiple times. , and plus using ping for intentional delay, which creates the effect of characters appearing one by one; in addition, the delay time of ping /n 1 127.1 running at different times here is different, which should be related to the IP address 127.1, and it has not been finally determined.


───────────────── Moderation Notice ─────────────────
The content shown in red is currently identified as incorrect remarks. Please pay attention!
For detailed content, please refer to Brief Analysis of Wunaike's Signature Code
http://www.cn-dos.net/forum/viewthread.php?tid=18838
───────────────── Moderation Notice ─────────────────


[ Last edited by willsort on 2006-1-21 at 22:50 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 3 Posted 2005-12-01 23:13 ·  中国 福建 漳州 电信
中级用户
★★
带走
Credits 435
Posts 88
Joined 2005-09-24 19:22
20-year member
UID 42793
Status Offline
Thanks to the hint from user willsort, I seem to understand something, but I still don't know why when I use "set t=abc & echo %t%", the first time I get "%t%" instead of "abc". Is it that the two statements are executed together instead of the statement before "&" being executed first and then the one after?
Floor 4 Posted 2005-12-01 23:19 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re 0401:

Sorry! I didn't notice your reply in time and made some supplements to the issues you mentioned in the original post.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 5 Posted 2005-12-02 00:34 ·  中国 辽宁 锦州 中移铁通
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
21-year member
UID 40733
Gender Male
Status Offline
The role is to make the variable that takes part of the string take effect.

ping/n 1 127.1 and ping/n 1 127.0.0.1 are equivalent.

I made two versions. Due to the 200-character limit for the signature, the other one couldn't be posted.

My requirements for this signature code are one is to try to have the shortest characters and the other is to try to be obscure and hard to read.

Try this under CMD, it's the same length as my current signature.

cls&(set,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul)&set,=

  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 6 Posted 2005-12-02 09:22 ·  中国 福建 漳州 电信
中级用户
★★
带走
Credits 435
Posts 88
Joined 2005-09-24 19:22
20-year member
UID 42793
Status Offline
My doubts have all been resolved. Thank you everyone!

And thanks to Brother Wunaike for providing the obscure and hard-to-read code ^_^ I discovered many usages that I didn't notice before
Floor 7 Posted 2005-12-02 12:42 ·  中国 山西 太原 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Originally posted by Wunaike at 2005-12-2 00:34:
Ping /n 1 127.1 and ping /n 1 127.0.0.1 are equivalent.


Re: Wunaike:

In that case, then you can refer to my discussion here about the latency effect of ping. The Oddity of Batch Programming – Mathematics (http://www.cn-dos.net/forum/viewthread.php?tid=8905#pid54227), see if it can explain the doubts I mentioned in it or correct the errors, and please reply to The Oddity of Batch Programming (http://www.cn-dos.net/forum/viewthread.php?tid=12388).

[ Last edited by willsort on 2005-12-2 at 12:45 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 8 Posted 2005-12-04 11:32 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 866
Posts 415
Joined 2005-12-04 11:19
20-year member
UID 46459
Status Offline
The batch processing of DOS has reached such a level, I really admire it.
Floor 9 Posted 2005-12-05 13:44 ·  中国 北京 顺义区 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
(set t=abc)&echo %t%
The LZ is really funny. Of course it won't work like that. Don't forget there's a space after set. Of course this line won't run, only the following statements will. You can try the above one and you'll know. A bit careless when writing!
Floor 10 Posted 2006-11-06 03:21 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
(set t=abc)&echo %t% doesn't work either. The effect is the same as set t=abc&echo %t%, both correctly display only when run the second time. Brother bagpipe, have you tested it?

[ Last edited by tianzizhi on 2006-11-6 at 03:22 AM ]
Floor 11 Posted 2007-03-17 22:21 ·  中国 上海 黄浦区 电信
初级用户
Credits 49
Posts 22
Joined 2005-08-04 13:44
20-year member
UID 41332
Gender Male
Status Offline
Delayed variable expansion effect
Floor 12 Posted 2007-03-18 01:35 ·  中国 上海 黄浦区 电信
初级用户
Credits 49
Posts 22
Joined 2005-08-04 13:44
20-year member
UID 41332
Gender Male
Status Offline
An expert is an expert
Floor 13 Posted 2007-03-18 01:58 ·  中国 广东 广州 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
Reading the analysis by the masters is simply a pleasure!
Floor 14 Posted 2007-03-25 23:35 ·  中国 青海 西宁 电信
新手上路
Credits 16
Posts 8
Joined 2007-03-25 08:59
19-year member
UID 82860
Gender Male
Status Offline
set t=abc & call & echo %t%

Is this okay!
Floor 15 Posted 2007-03-28 00:39 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 186
Posts 92
Joined 2007-03-27 08:20
19-year member
UID 83047
Gender Male
Status Offline
The upstairs is still not okay. You need to add the variable delay command in front.

@echo off&setlocal EnableDelayedExpansion
set t=abc&echo !t!
pause
Forum Jump: