函数和标签的使用

实例1:
@echo off 
echo the name of the bat file is  %0
echo the first vars of the bat file is  %1
call:function1
call:function2
call:function2
call:function3
call:function4 robin
goto LabelEnd
echo this should not be seen
:LabelEnd
exit /b 0 
:function1 
echo:1 
exit /b 0 
:function2
echo:2  
exit /b 0  
:function3
echo:3 
exit /b 0
:function4
echo: 函数名是 %0
echo:the first vars of function is  %1
exit /b 0
注意1:exit的使用。
Quits the CMD.EXE program (command interpreter) or the current batch script.
EXIT [/B] [exitCode]
   /B          specifies to exit the current batch script instead of
              CMD.EXE.  If executed from outside a batch script, it
              will quit CMD.EXE
   exitCode    specifies a numeric number.  if /B is specified, sets
              ERRORLEVEL that number.  If quitting CMD.EXE, sets the process
              exit code with that number.
exitCode可以通过系统变量ERRORLEVEL取得
注意2:函数和标签的定义一样, 只是调用方式不一样。函数用call:+函数名的形式,比如call:function1。
标签使用goto LabelEnd的形式。函数还有可以 传递参数比如:call:function4 robin,而标签不行。
函数调用有 返回值,而标签没有。

猜你喜欢

转载自zzc1684.iteye.com/blog/2217030
今日推荐