`
zzc1684
  • 浏览: 1192104 次
  • 性别: Icon_minigender_1
  • 来自: 广州
文章分类
社区版块
存档分类
最新评论

函数和标签的使用

阅读更多
实例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,而标签不行。
函数调用有返回值,而标签没有。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics