Converting DOS Batch Files to Shell Scripts

** Credit Web
Table 1. Batch file keywords / variables / operators, and their shell equivalents
Batch File OperatorShell Script EquivalentMeaning
%$command-line parameter prefix
/-command option flag
\/directory path separator
===(equal-to) string comparison test
!==!!=(not equal-to) string comparison test
||pipe
@set +vdo not echo current command
**filename "wild card"
>> file redirection (overwrite)
>>>> file redirection (append)
<< redirect stdin
%VAR%$VARenvironmental variable
REM#comment
NOT!negate following test
NUL/dev/null"black hole" for burying command output
ECHOechoecho (many more option in Bash)
ECHO.echoecho blank line
ECHO OFFset +vdo not echo command(s) following
FOR %%VAR IN (LIST) DOfor var in [list]; do"for" loop
:LABELnone (unnecessary)label
GOTOnone (use a function)jump to another location in the script
PAUSEsleeppause or wait an interval
CHOICEcase or selectmenu choice
IFifif-test
IF EXIST FILENAMEif [ -e filename ]test if file exists
IF !%N==!if [ -z "$N" ]if replaceable parameter "N" not present
CALLsource or . (dot operator)"include" another script
COMMAND /Csource or . (dot operator)"include" another script (same as CALL)
SETexportset an environmental variable
SHIFTshiftleft shift command-line argument list
SGN-lt or -gtsign (of integer)
ERRORLEVEL$?exit status
CONstdin"console" (stdin)
PRN/dev/lp0(generic) printer device
LPT1/dev/lp0first printer device
COM1/dev/ttyS0first 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 2. DOS commands and their UNIX equivalents
DOS CommandUNIX EquivalentEffect
ASSIGNlnlink file or directory
ATTRIBchmodchange file permissions
CDcdchange directory
CHDIRcdchange directory
CLSclearclear screen
COMPdiff, comm, cmpfile compare
COPYcpfile copy
Ctl-CCtl-Cbreak (signal)
Ctl-ZCtl-DEOF (end-of-file)
DELrmdelete file(s)
DELTREErm -rfdelete directory recursively
DIRls -ldirectory listing
ERASErmdelete file(s)
EXITexitexit current process
FCcomm, cmpfile compare
FINDgrepfind strings in files
MDmkdirmake directory
MKDIRmkdirmake directory
MOREmoretext file paging filter
MOVEmvmove
PATH$PATHpath to executables
RENmvrename (move)
RENAMEmvrename (move)
RDrmdirremove directory
RMDIRrmdirremove directory
SORTsortsort file
TIMEdatedisplay system time
TYPEcatoutput file to stdout
XCOPYcp(extended) file copy

0 comments:

Loading