Bat batch script program <three> delayed variable expansion and Call

original

Go straight to the script, it's not difficult, but it's a bit of a headache. There are not many things about Bat, and there are quite a lot of things. It’s almost enough to learn the basics. I don’t want to go deeper. I can understand and modify a little. For example, compiling COCOS games or something, copying files in batches or something , After watching it for two or three days, I don't think it's a waste of time.


Call practice.bat

@echo off
:: %0 是脚本自身 
echo 你调用了  %0
echo 传过来的第一个参数是:  %1 第二个参数是:  %2 

set /a BBB=888

pause

variable delay.bat

@echo off

::1.Call
::调用  练习.bat  参数1:100   参数2:我是大帅哥
call D:\Call练习.bat 100 我是大帅哥 
::可以直接继承变量BBB
echo %BBB%
::调用完成后,继续执行
pause


::2.没有开启变量延迟扩展
set /a AAA=0
for /L %%a in (1,1,5) do (
    set /a AAA=%%a
    ::这里的 AAA 永远等于0,因为do()后面复合语句,所有的命令是相当于一条命令来执行,相当于所有命令并行
    echo %AAA%
)
::这里AAA=5
echo %AAA%
pause


::3.开启变量延迟扩展
setlocal EnableDelayedExpansion 

set /a AAA=0
for /L %%a in (1,1,5) do (
    set /a AAA=%%a
    ::开启变量延迟扩展后,用!AAA!来取值,%AAA%还是等于0
    echo !AAA!
)
::这里AAA=5
echo %AAA%
pause


//Change the working directory to F drive
pushd F:\   

//Back to the current directory ( %~dp0 )
popd


Script download:

http://download.csdn.net/download/u012322710/10190451


Guess you like

Origin blog.csdn.net/u012322710/article/details/78982780