Converting DOS Batch Files to Shell Scripts

Appendix H. 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.

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.

Virtually all UNIX and shell operators and commands have many more options and enhancements than their DOS and batch file equivalents. Many DOS batch files rely on auxiliary utilities, such as ask.com, a crippled counterpart to read.

DOS supports a very limited and incompatible subset of filename wildcard expansion, recognizing only the * and ? characters.

Converting a DOS batch file into a shell script is generally straightforward, and the result ofttimes reads better than the original.

The script conversion is somewhat of an improvement.

Ted Davis' Shell Scripts on the PC site has a set of comprehensive tutorials on the old-fashioned art of batch file programming. Certain of his ingenious techniques could conceivably have relevance for shell scripts.