![]() |
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-08-12 12:46 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » Why does this batch file end up showing two "one"s? |
| Printable Version 831 / 2 |
| Floor1 gool123456 | Posted 2010-04-12 00:44 |
| 初级用户 Posts 76 Credits 89 | |
|
@echo off
set a=one set b=two echo/Before call :swap a b call :Swap a b echo/After call 1 :swap a b call :Swap b a echo/After call 2 :swap b a pause goto :EOF :Swap call set a=%%%1%% call set b=%%%2%% set "%1=%b%" & set "%2=%a%" & goto :EOF ---------------------------------------------------------------------- Displayed result: Before call :swap a b After call 1 :swap a b After call 2 :swap b a I really can't figure it out, please explain.. |
|
| Floor2 Hanyeguxing | Posted 2010-04-12 03:24 |
| 银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂 | |
|
When it gets to echo/After call 2 :swap b a
call set a=%%%1%% call set b=%%%2%% because %1=b, %2=a that is, set a=!b! set b=!a! so as far as the values are concerned, !a!=!b!=one [ Last edited by Hanyeguxing on 2010-4-12 at 14:04 ] |
|
| Floor3 gool123456 | Posted 2010-04-12 17:18 |
| 初级用户 Posts 76 Credits 89 | |
|
Your reply again, thanks first of all!!
Oh, so that's how it is!! I was treating the variables brought in by CALL as values and doing call set on them, no wonder two disappeared... uh |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |