bat 脚本之 使用函数
来源:互联网 发布:nodejs数据返回页面 编辑:程序博客网 时间:2024/06/08 18:34
- 综述
- bat函数写法
- bat函数调用
- bat函数返回值
综述
Windows bat脚本是一种解释性的脚本语言,可以拿到做很多事情。对于稍简单的问题:比如通过注册表判断下档期机器的语言啊,国家啊,安装了那些软件啊等等还少诶简单。但是如果有可能使用bat脚本来处理较复杂的问题时,就需要用函数来将其模块化,方便bat脚本的阅读和编写。下面来介绍下bat 函数的用法
bat函数写法
如下是一个最简单的函数写法;以:func
开始以goto:eof
结束。:func
和goto:eof
之间的为函数内容,例如这里的echo this is a bat func
:funcecho this is a bat funcgoto:eof
bat函数调用
写好了bat函数之后,我们需要调用它。如下代码片段展示了如何在bat脚本中调用函数。其实很简单,就这一句call:func
即可。
call:funcpause:funcecho this is a bat funcgoto:eof
bat函数返回值
目前我了解到的bat函数返回值的获取有如下两种方法:
- 使用参数带回
- 使用全局变量带回
这里直接贴上关于bat函数的各种条件的验证代码
echo offcolor 0decho bat Function exampleecho =================================echo ==========Func No paramter ======echo =================================echo before call myFuncNoParacall:myFuncNoParaecho after call myFuncNoParaecho =================================echo ===========Func has paramter=====echo =================================echo before call myFuncHasParacall:myFuncHasPara 123 abcecho after call myFuncHasParaecho =================================echo =======Func with return value====echo =================================set return=123set returnPara=321echo return:%return%echo returnPara:%returnPara%echo befora call myFuncReturnValuecall:myFuncReturnValue returnPara abcecho after call myFuncReturnValueecho return:%return%echo returnPara:%returnPara%pause:myFuncNoParaecho myFuncNoPara enterecho myFuncNoPara First para:%1echo myFuncNoPara Second para:%2echo myFuncNoPara Third para:%3echo myFuncNoPara exitgoto:eof:myFuncHasParaecho myFuncHasPara enterecho myFuncHasPara First para:%1echo myFuncHasPara Second para:%2echo myFuncHasPara Third para:%3echo myFuncHasPara exitgoto:eof:myFuncReturnValueecho myFuncReturnValueecho myFuncReturnValue First para:%1echo myFuncReturnValue Second para:%2set "%~1=%2%"set return=%2goto:eof
运行效果图
阅读全文
0 0
- bat 脚本之 使用函数
- bat脚本使用记录
- bat脚本之垃圾清理
- CMD命令之BAT脚本语法详解
- Android打包之bat脚本打包
- 自动化脚本之bat管理IP地址
- Android打包之bat脚本打包
- CMD命令之BAT脚本路径信息
- Windows bat脚本for循环之二
- bat 脚本之获取当前时间
- Windows脚本 - Bat批处理命令使用教程
- 使用bat方式执行sql脚本
- 使用BAT脚本启动android模拟器
- 使用bat方式执行sql脚本
- Windows脚本 - Bat批处理命令使用教程
- 使用Android.bat生成ant打包脚本
- 使用bat脚本操作Oracle数据库,导入
- 使用bat脚本进行数据库操作
- apache日志获取代理后用户真实IP
- IOC控制反转
- shell学习第一天
- 灵活运用浏览器
- 编程模拟飞船加速变轨过程-物理基础篇(3)Kepler轨道及其描述(上)
- bat 脚本之 使用函数
- Using Predefined CSS Margin Classes
- spring原理
- Linux环境下C++单元测试Gtest 入门
- Tinker原理深入理解(二)
- BZOJ 4525: [Usaco2016 Jan]Angry Cows 二分
- NodeJS -- 异步I/O
- Word2003快速操作技巧及常用快捷键使用
- PowerPC家族谱系详解