Converting DOS Batch Files to Shell Scripts

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
@set +vdo not echo current command
**filename “wild card”
>>file redirection (overwrite)
>>>>file redirection (append)
<<redirect stdin
%VAR%$VARenvironmental variable
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
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



BASH Programming – Introduction HOW-TO

Bit old but extremely useful for beginners:

1. Introduction

2. Very simple Scripts

3. All about redirection

4. Pipes

5. Variables

6. Conditionals

7. Loops for, while and until

8. Functions

9. User interfaces

10. Misc

11. Tables

12. More Scripts

13. When something goes wrong (debugging)

14. About the document