bash和batch指令对比

功能描述 bash命令 batch命令
查看当前目录 pwd cdecho %cd%
列出目录内容 ls dir
更改目录 cd <directory> cd <directory>
创建新目录 mkdir <directory> mkdirmd <directory>
删除文件 rm <file> del <file>
删除目录 rmdir <directory>rm -r <directory> rmdir <directory>rd <directory>
复制文件 cp <source> <destination> copy <source> <destination>
移动或重命名文件 mv <source> <destination> move <source> <destination>ren <source> <new name>
设置环境变量 export VAR=value set VAR=value
执行另一个脚本或程序 ./<script.sh> <script.bat>call <script.bat>
显示文本 echo <text> echo <text>
附加到文件 echo <text> >> <file> echo <text> >> <file>
从文件读取 cat <file> type <file>
查找文本 grep <pattern> <file> find "<string>" <file>
获取命令输出 command$(command) %command%
条件语句 if [ condition ]; then ... fi if <condition> ( ... )
循环 for var in <list>; do ... done for %var in (<list>) do ...
当前用户名 whoami echo %username%
临时停止脚本 sleep <seconds> timeout /t <seconds>
文件存在检查 if [ -f <file> ]; then ... fi if exist <file> ( ... )