![]() |
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-13 22:40 |
47,812 topics / 349,916 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » [Solved] About the delay in variable substitution of "set & echo" |
| Printable Version 6,184 / 21 |
| Floor1 0401 | Posted 2005-12-01 20:27 |
| 中级用户 Posts 88 Credits 435 | |
|
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 ] |
|
| Floor2 willsort | Posted 2005-12-01 22:33 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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 ] |
|
| Floor3 0401 | Posted 2005-12-01 23:13 |
| 中级用户 Posts 88 Credits 435 | |
|
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?
|
|
| Floor4 willsort | Posted 2005-12-01 23:19 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re 0401:
Sorry! I didn't notice your reply in time and made some supplements to the issues you mentioned in the original post. |
|
| Floor5 无奈何 | Posted 2005-12-02 00:34 |
| 荣誉版主 Posts 356 Credits 1,338 | |
|
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. |
|
| Floor6 0401 | Posted 2005-12-02 09:22 |
| 中级用户 Posts 88 Credits 435 | |
|
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 |
|
| Floor7 willsort | Posted 2005-12-02 12:42 |
| 元老会员 Posts 1,512 Credits 4,432 | |
Originally posted by Wunaike at 2005-12-2 00:34: 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 ] |
|
| Floor8 htysm | Posted 2005-12-04 11:32 |
| 高级用户 Posts 415 Credits 866 | |
|
The batch processing of DOS has reached such a level, I really admire it.
|
|
| Floor9 bagpipe | Posted 2005-12-05 13:44 |
| 银牌会员 Posts 425 Credits 1,144 From 北京 | |
|
(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! |
|
| Floor10 tianzizhi | Posted 2006-11-06 03:21 |
| 高级用户 Posts 214 Credits 623 | |
|
(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 ] |
|
| Floor11 jianyaogao | Posted 2007-03-17 22:21 |
| 初级用户 Posts 22 Credits 49 | |
|
Delayed variable expansion effect
|
|
| Floor12 jianyaogao | Posted 2007-03-18 01:35 |
| 初级用户 Posts 22 Credits 49 | |
|
An expert is an expert
|
|
| Floor13 axi | Posted 2007-03-18 01:58 |
| 中级用户 Posts 93 Credits 238 From GZ | |
|
Reading the analysis by the masters is simply a pleasure!
|
|
| Floor14 kkoper | Posted 2007-03-25 23:35 |
| 新手上路 Posts 8 Credits 16 | |
|
set t=abc & call & echo %t%
Is this okay! |
|
| Floor15 lp1129 | Posted 2007-03-28 00:39 |
| 初级用户 Posts 92 Credits 186 | |
|
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 |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |