比较符号(不能用 < , >)

The reason operators like > are not used is because they have special meanings in shell scripts. The > is used to redirect output; < used to redirect input, etc.

  1. Operator | Description
  2. EQU | equal to
  3. NEQ | not equal to
  4. LSS | less than
  5. LEQ | less than or equal to
  6. GTR | greater than
  7. GEQ | greater than or equal to

%* 命令

Key point:

  • It means "all the parameters in the command line".
  • %* expands to all parameters from the command line, even after a SHIFT operation. Normally a SHIFT will move parameter %2 to %1%3 to %2, etc., and %1 is no longer available. But %* ignores any SHIFT, so the complete parameter list is always available. This can be both a blessing and a curse.

Usage:

  • it's useful when you want to forward the command line from your batch file to another program

Shift 命令

shift command shifts the position of arguments one to the left. Running shift once in a batch file will make "%1" value to be the second argument, "%2" becomes the third, and so on. It's useful for processing command line arguments in a loop in the batch file.

Attention:

  • Shift doesn't change the actual order, just the index/pointer into the arguments.
  • It doesn't affect %*

Command like:

  1. c:/>batchName.bat a b c d

batName.bat content:

  1. @echo off
  2. echo %
  3. shift
  4. echo %
  5. shift
  6. echo %
  7. echo %*

And you get this:

  1. a
  2. b
  3. c
  4. a b c d

%0、%1等是表示什么

%0 指批处理本身。

%1 指批处理文件名后加的以空格分隔的字符串。

%2~%9类推

比如说

D盘根目录下有aa.txt,bb.txt,cc.txt三个文本和一个名batName.bat的批处理,批处理内容是

@echo off

start %1

start %3

打开CMD定位到D盘

D:\>batName     aa.txt    bb.txt    cc.txt

对应:       %0            %1       %2        %3

就会打开aa.txt(它是第一个参数即%1)和cc.txt(它是第三个参数即%3),而不会打开bb.txt,因为批处理的命令里没有start %2(bb.txt排第二所以是第二个参数)

%2 与 %~2 的区别

%2 substitutes in the second argument. %~2 substitutes the second argumenty but removes any quote marks:

  1. C:\Temp>type t.cmd
  2. @echo off
  3. echo %%2 is: %2
  4. echo %%~2 is: %~2
  5. C:\Temp>t.cmd first second third
  6. %2 is: second
  7. %~2 is: second
  8. C:\Temp>t.cmd first "second third"
  9. %2 is: "second third"
  10. %~2 is: second third

echo off和echo on的作用

先写一个批处理文件,命令很简单,只是打印语句,如下:

  1. rem 我把"执行echo off""执行echo on"也打印出来了,对了,前面的 rem 相当于java注释中的//
  2. echo 第一句
  3. echo 第二句
  4. echo 第三句
  5. echo off
  6. echo 执行echo off
  7. echo 第一句
  8. echo 第二句
  9. echo 第三句
  10. echo on
  11. echo 执行echo on
  12. echo 第一句
  13. echo 第二句
  14. echo 第三句

然后是运行结果,图中有说明:

执行”echo off”,后面所执行的命令不会显示出来,只会显示结果.

但”echo off”本身的命令会显示出来怎么办,所以一般见到的echo off 前面都有”@”,”@”作用是此行所有的命令都不显示,只执行,和”echo off”比较相似,不过只对当前行起作用

————————————————

版权声明:本文为CSDN博主「S_clifftop」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/S_clifftop/article/details/78632313

版权声明:本文为CSDN博主「rainbow702」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/rainbow702/article/details/50516739

Batch - Windows Batch 常用命令的更多相关文章

  1. Windows运行常用命令(win+R)

    Windows运行常用命令(win+R) 1.calc: 启动计算器 2.notepad: 打开记事本 3.write: 写字板 4.mspaint: 画图板 5.snippingtool:截图工具, ...

  2. windows CMD常用命令

    命令简介 cmd是command的缩写.即命令行 . 虽然随着计算机产业的发展,Windows 操作系统的应用越来越广泛,DOS 面临着被淘汰的命运,但是因为它运行安全.稳定,有的用户还在使用,所以一 ...

  3. Windows CMD常用命令大全 运行命令

    http://blog.163.com/lixunhuan@126/blog/static/122060620075124142658/ CMD命令大全 net use \\ip\ipc$ " ...

  4. Windows&Linux常用命令笔记

    目录 linux windows Linux: 1.查找文件 find / -name filename.txt 根据名称查找/目录下的filename.txt文件. find . -name &qu ...

  5. windows系统常用命令

    dir 指定要列出的驱动器,显示当前文件夹下的文件   /?可显示所有命令 显示当前路径下的所有文件的绝对路径,包含子文件夹中的内容 D:\test > dir /b /s /o:n /a:a  ...

  6. Batch - windows batch 常用命令(cheat sheet)

    原文地址:https://www.oschina.net/code/snippet_158297_4964 1 echo 和 @ 回显命令 @ #关闭单行回显 echo off #从下一行开始关闭回显 ...

  7. 《自拍教程13》Windows的常用命令

    这些是Windows系统自带的常用DOS命令集合, 先大概了解下,当然如果能熟练掌握那最好了. 后续思维篇,思维篇还会结合不通的测试场景, 届时将列出这些命令更详细的使用描述. table.dataf ...

  8. Windows CMD常用命令集合

    CMD命令: 开始->运行->键入cmd或command(在命令行里可以看到系统版本.文件系统版本) chcp 修改默认字符集chcp 936默认中文chcp 65001 1. appwi ...

  9. 【原】Windows下常用命令

    1.小技巧 打开"运行"对话框(Win+R),输入cmd,打开控制台命令窗口... 也可以通过cmd /c 命令 和 cmd /k 命令的方式来直接运行命令 注:/c表示执行完命令 ...

随机推荐

  1. html5本地存储(二)--- SQLList

    html5内置了2种本地数据库,一是被称为“SQLLite”,可以通过SQL语言来访问文件型SQL数据库.二是被称为“indexedDB” 的NoSQL类型的数据库 这篇主要讲SQLLite 在js中 ...

  2. mysql数据库中某字段一部分乱码

    笔者问题:mysql表(表中数据就是乱码,可能是插入时编码问题,这个问题以后解决)导出excel时数据中有乱码(但是在页面上查看是正常的),我们希望能导出一份没有中文乱码的excel 根据热力站中一次 ...

  3. OneDrive一直后台占用CPU的一种解决办法

    系统版本:Windows 7 ultimate x64 Onedrive版本:17.3.6998.0830 最近发现Onedrive一直在后台占用15%左右的CPU,很是觉得奇怪,网上的解决方案是删除 ...

  4. 笔记38 Spring Web Flow——订单流程(定义基本流程)

    做一个在线的披萨订购应用 实际上,订购披萨的过程可以很好地定义在一个流程中.我们首先从 构建一个高层次的流程开始,它定义了订购披萨的整体过程.接下 来,我们会将这个流程拆分成子流程,这些子流程在较低的 ...

  5. K-mean matlab 实现代码

    一.K均值聚类算法 算法步骤如下: 1.初始化 已知数据集合X,及事先指定聚类的总类数N,在X中随机选取N个对象作为初始的聚类中心. 2.设定迭代终止条件 通常设置最大循环次数或者聚类中心的变化误差. ...

  6. Laravel Route Resource 方法

    新增的 resource 方法将遵从 RESTful 架构为用户资源生成路由.该方法接收两个参数,第一个参数为资源名称,第二个参数为控制器名称. Route::resource('users', 'U ...

  7. top.location.href

    window.location.href.location.href是本页面跳转   parent.location.href是上一层页面跳转   top.location.href是最外层的页面跳转 ...

  8. PHP PDO 大对象 (LOBs)

    应用程序在某一时刻,可能需要在数据库中存储"大"数据. "大"通常意味着"大约 4kb 或以上",尽管某些数据库在数据达到"大&q ...

  9. php给每个数组元素加上前缀

    比如原数组是 array('1','2','3','4'); 我需要得到的结果 array('aaa1','aaa2','aaa3','aaa4'); 用内置函数如何实现? array_walk() ...

  10. Android源码的git下载地址

    git clone https://android.googlesource.com/device/common.git    git clone https://android.googlesour ...