文档章节

Appendix L. Converting DOS Batch Files to Shell...

tadcat
 tadcat
发布于 2013/07/28 21:06
字数 363
阅读 20
收藏 0

Advanced Bash-Scripting Guide:
Prev Next

http://www.tldp.org/LDP/abs/html/dosbatch.html

--------------------------------------------------------------------------------

Appendix L. Converting DOS Batch Files to Shell Scripts

Quite a number of programmers learned scripting on a PC running DOS. Even the crippled DOS batch file language allowed writing some fairly powerful scripts and applications, though they often required extensive kludges and workarounds. Occasionally, the need still arises to convert an old DOS batch file to a UNIX shell script. This is generally not difficult, as DOS batch file operators are only a limited subset of the equivalent shell scripting ones.

Table L-1. Batch file keywords / variables / operators, and their shell equivalents

Batch File Operator Shell Script Equivalent Meaning
% $ command-line parameter prefix
/ - command option flag
/ directory path separator
== = (equal-to) string comparison test
!==! != (not equal-to) string comparison test
| | pipe
@ set +v do not echo current command
* * filename "wild card"
> > file redirection (overwrite)
>> >> file redirection (append)
< < redirect stdin
%VAR% $VAR environmental variable
REM # comment
NOT ! negate following test
NUL /dev/null "black hole" for burying command output
ECHO echo echo (many more option in Bash)
ECHO. echo echo blank line
ECHO OFF set +v do not echo command(s) following
FOR %%VAR IN (LIST) DO for var in [list]; do "for" loop
:LABEL none (unnecessary) label
GOTO none (use a function) jump to another location in the script
PAUSE sleep pause or wait an interval
CHOICE case or select menu choice
IF if if-test
IF EXIST FILENAME if [ -e filename ] test if file exists
IF !%N==! if [ -z "$N" ] if replaceable parameter "N" not present
CALL source or . (dot operator) "include" another script
COMMAND /C source or . (dot operator) "include" another script (same as CALL)
SET export set an environmental variable
SHIFT shift left shift command-line argument list
SGN -lt or -gt sign (of integer)
ERRORLEVEL $? exit status
CON stdin "console" (stdin)
PRN /dev/lp0 (generic) printer device
LPT1 /dev/lp0 first printer device
COM1 /dev/ttyS0 first serial port

Batch files usually contain DOS commands. These must be translated into their UNIX equivalents in order to convert a batch file into a shell script.

Table L-2. DOS commands and their UNIX equivalents

本文转载自:

tadcat

tadcat

粉丝 16
博文 969
码字总数 155502
作品 0
石景山
私信 提问
Java Sound Programmer Guide

Introductory Material Preface For Whom This Guide Is Intended What this Guide Describes For More Information Chapter: 1 Introduction to the Java Sound APIDesign Goals Who is the......

祖冲之
2018/12/11
0
0
解决Winword意外关闭的问题

你遇到没遇到过“Microsoft Office Word 遇到问题需要关闭。我们对此引起的不便表示抱歉”的提示呢?然后有一个“恢复我的工作并重启 Microsoft Office Word”的选择框,并将此问题发送报告给...

lintur
2009/09/24
1K
0
在右键菜单中添加Dos快捷通道-dos在这里

在右键菜单中添加Dos快捷通道-dos在这里 在右键菜单中添加 Dos 窗体 不用每次都要到运行去使用cmd调用再cd 到目录下面了。 方法一: 1.在资源管理器中 工具–>选项–>文件类型 2.列表选择:资...

jessehwong
2010/11/12
0
0
Shell脚本之编码格式问题

shell脚本异常:/bin/sh^M:bad interpreter: No such file or directory 把sh脚本在windows下修改了下,放到linux下,总是运行不能成功,每个命令的最后都被加了一个M,查找了下,原因是因为...

90xa
2016/06/30
409
0
在右键菜单中添加Dos快捷通道-dos在这里

在右键菜单中添加Dos快捷通道-dos在这里 在右键菜单中添加 Dos 窗体 不用每次都要到运行去使用cmd调用再cd 到目录下面了。 方法一: 1.在资源管理器中 工具–>选项–>文件类型 2.列表选择:资...

jessehwong
2010/11/12
3.4K
4

没有更多内容

加载失败,请刷新页面

加载更多

Android ANR原理分析

一、概述 ANR(Application Not responding),是指应用程序未响应,Android系统对于一些事件需要在一定的时间范围内完成,如果超过预定时间能未能得到有效响应或者响应时间过长,都会造成ANR...

天王盖地虎626
20分钟前
1
0
IT兄弟连 Java语法教程 Java开发环境 安装JDK

因为我们要开发Java程序,所以必须在我们的计算机中安装Sun(Oracle)公司提供给我们的JDK。目前最新版本的JDK是JDK 10,但是我们以学习JDK 8为主,所以我们要安装的版本是JDK 8。安装步骤如...

老码农的一亩三分地
26分钟前
0
0
Spring Boot Repository查询条件关键字

查询条件关键字 Keyword Sample JPQL snippet And findByLastnameAndFirstname … where x.lastname = ?1 and x.firstname = ?2 Or findByLastnameOrFirstname … where x.lastname = ?1 or......

兜兜毛毛
32分钟前
0
0
[js]closeure闭包

// // closure 1 function func() { var count = 0; function cal(){ count += 2; console.log(count); return count; ......

Danni3
32分钟前
0
0
centos 设置hostname

1、centos 6 hostname配置文件为 /etc/sysconfig/network 内容为 NETWORKING=yesHOSTNAME=test_hostname hostname是Linux系统下的一个内核参数,它保存在 /proc/sys/kernel/hostname 下,但......

燃犀
58分钟前
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部