现在的位置: 首页 > 综合 > 正文

bat备忘

2017年12月21日 ⁄ 综合 ⁄ 共 657字 ⁄ 字号 评论关闭

1.参数传递

编辑:

@echo off

set param1=%1
set param2=%2

echo 参数1:%param1%
echo 参数2:%param2%

pause

运行:

扩展:

当传递的参数存在空格,调用时应用双引号""包括起来,因为bat一遇到空格便认为当前参数已输入完毕

例如我们传递C:\Program Files\myapp1.exe和C:\Program Files\myapp2.exe,引号对运行结果影响如下

2.if语句

编辑:

@echo off
echo 演示if命令的使用
echo ***************************************
if exist a.txt (echo file a exist
) else (echo file a not exist)
echo ***************************************
if not exist a.txt (echo file a not exist
) else (echo file a exist)
echo ***************************************



运行:


扩展:

else的命令必须与if命令的尾端在同一行上

// 这不是一个bat文件,只做说明用

正确1:
if exist a.txt (del file) else (echo file a not exist)

正确2:
if exist a.txt (del file
) else (echo file a not exist)

错误1:
if exist a.txt (del file) 
else (echo file a not exist)



抱歉!评论已关闭.