Tuesday, May 27, 2008

Running UNIX Applications on DOS/Windows Machines

Running the Shell as a Program Under COMMAND.COM

Although you can run look-alike tools directly under the standard DOS/Windows command interpreter, COMMAND.COM, running a version of the UNIX shell on Windows can be very useful. Compared to COMMAND.COM, the UNIX shell is much more powerful and flexible, both as a command interpreter and as a programming language for writing scripts. Using the shell in place of or in addition to COMMAND.COM provides a more complete UNIX-style environment, including such valuable shell features as command-line editing and shell programming constructs. Furthermore, using the shell enables you to make use of some features of the look-alike tools that may not run properly under COMMAND.COM. One example is the capability to use commands that span more than one line, as in awk and sed commands. The UNIX System look-alike tools include versions of the shell. The MKS Toolkit includes the Korn shell.

The easiest way to run the shell on your DOS/Windows system is as a program running under COMMAND.COM-that is, you continue to use COMMAND.COM as your normal command interpreter, and when you want to use the shell, you invoke it as you would any other command.

To run the shell using the MKS Toolkit, type the following at the DOS prompt:

 C:\> Sh
$

You will see the UNIX System prompt, which is by default a dollar sign. You then enter commands, with their options and filenames, just as you would in a UNIX System environment. For example, using sh rather than COMMAND.COM you can enter multiline arguments on the command line, which you need for awk and other commands. To exit the shell and return to COMMAND.COM, type exit.

This way of running the shell does not replace COMMAND.COM; it simply uses COMMAND.COM to run sh, which then acts as your command interpreter. This has the advantage of providing the most completely consistent DOS environment, for example, when a program requires you to use the DOS-style indicator for command options (slash), rather than the minus sign used on the UNIX System and by the shell. If you run the shell under COMMAND.COM, you can simply exit from the shell in order to run these particular programs.

If you want to execute the DOS equivalent of a .profile (similar to the environment set up in your AUTOEXEC.BAT) when you start the shell, you can invoke it with the L option:

C:\> Sh −L
$

This will set up any environmental variables you choose to specify in your profile.ksh file.

No comments: