.nr N 2
.tr ~
.S 12 14
.de TP
'sp 3
.ie e \{ .po -.375i
.tl '\\nP''\f3DSH\f1' \}
.el \{ .po +.375i
.tl '\f3DSH\f1''\\nP' \}
'sp 2
..
.DS C
.B
The DOS Shell (dsh)

.R
D. B. Preston
W. M. Brelsford

\*(DT
.SP 3
.DE
.H 1 Introduction
The DOS shell is a set of UNIX\*F
.FS
UNIX is a trademark of AT&T.
.FE
commands that emulate the syntax and function of MS-DOS\*F
.FS
MS-DOS is a trademark of Microsoft Corp.
.FE
commands.
The emulation does not extend to reproducing the output of the
DOS commands exactly, but rather provides the same functionality
to the extent possible or appropriate.
In addition to the DOS commands, all UNIX System V commands are also available
to dsh, to the extent that they are not in direct conflict with DOS commands.
In some cases (e.g., the find command), the DOS and UNIX syntax is sufficiently
different that both are available simultaneously.
.P
The DOS-like environment is entered by typing ``dsh'' at the UNIX prompt,
or executing dsh at the bottom of the profile.
In addition to the complete set of DOS commands, dsh provides a command
(i.e., ``dtrace~on'' and ``dtrace~off'')
to print the System V command corresponding to the
given DOS command before execution.
This feature is a useful teaching aid for those familiar with DOS
who would like to learn UNIX painlessly.
The DOS shell is efficient, however, and could be used
by people who must use both DOS and UNIX, and would like a standard
command-level interface.
.H 1 "DOS commands"
A complete listing of DOS commands follows.
This manual is not intended to document the commands, but
rather to indicate which functions and options are supported by dsh.
As such, it is more of an ``exception~report,''  and must by read with
the DOS User's Guide.
The major differences are discussed below.
.P
Except for BREAK, FOR, IF, SET and TIME, all DOS
commands are recognized in lower as well as upper case.
Similarly, all DOS flags (e.g., /W in DIR) are recognized in both upper
and lower case.
Each flag must be preceded by a blank, however.
Unlike DOS, DIR/W will not be recognized by dsh, for example.
Since dsh is operating in the UNIX environment,
.B
slashes (rather than
back-slashes) denote directories.
.R
.P
DOS variables are denoted by percent signs, fore and aft (e.g., %file%).
In UNIX, variables are usually denoted by a leading dollar sign (e.g., $file),
but may have braces added (e.g., ${file}), if necessary to separate the
variable name from its context.
UNIX variables cannot contain blanks, however.
.P
Input and output redirection and pipes are syntactically 
equivalent in DOS and UNIX.
.P
The ``aliasing'' features of the Korn shell
(ksh) are used heavily by dsh, so
ksh must be available to run dsh.
All the features of ksh, to the extent they are not in conflict and
thus disabled by dsh, are available.
.H 2 "ASSIGN (assign)"
The DOS function of assign is to direct requests between disk drives.
The UNIX analog is mounting a new file system, and assigning it a name.
Thus ASSIGN is aliased with ``mount'', and a typical use would
be ``assign~/dev/floppy=/mnt''.
As with DOS, both the physical device (/dev/floppy in the example), and
the directory (/mnt) which is to become the root of the new file system, must
exist beforehand.
The UNIX command ``umount'' is then needed, and is equivalent to ASSIGN without
arguments.
.H 2 "BACKUP (backup)"
BACKUP backs up files or directories, using cpio.
In dsh, it operates to a directory, rather than a disk drive as in DOS.
The /P (pack) flag is ignored, and the /A (add) flag
will overwrite an existing file with the same name.
All other flags operate as in DOS.
.H 2 "BREAK"
BREAK turns on and off interpretation of CTRL-C as an interrupt,
exactly as in DOS.
The lower case version is reserved for the UNIX function (breaking out of
loops).
.H 2 "CD (cd)"
This a synonym of CHDIR (below).
.H 2 "CHDIR (chdir)"
Changing the active directory is done by the UNIX cd command, and
listing the current directory by the echo command.  ``CHDIR~/xyz'' will
change to directory xyz under the
user's HOME directory, or root (in order of
search); ``CHDIR~xyz'' searches the current
directory first, then the home directory.
Note: ``CHDIR~..'' from the /bin directory will get to the real root (i.e., /)
if necessary.
.P
UNIX file systems are the closest analog of DOS disk drives.
However, CHDIR is able to cross file systems, so there is no need for a
UNIX analog of the DOS command ``C:'' to change to the C disk.
.H 2 "CHKDSK (chkdsk)"
Disk consistency checking and repair is done by fsck.
All options are supported.
.H 2 "CLS (cls)"
Screen clearing is terminal dependent, so the UNIX TERMINFO variable must
be defined. This command requires System V, Release 2.
.H 2 "COMMAND (command)"
Calling another copy of the command processor is the equivalent
of dsh.
.H 2 "COMP (comp)"
Comparing files, or a group of files is done by cmp, with some help
from ls and xargs. The result is completely equivalent to the DOS version.
.H 2 "COPY (copy)"
The DOS COPY command is complex, with two primary syntaxes, one to copy
and one to append.
Both are supported by dsh.
The /V (verify), /B (binary), and /A (ASCII) flags are ignored, since they are
irrelevant for UNIX.
.H 2 "CTTY (ctty)"
CTTY works as documented in DOS.
See the section on reserved file names, however.
.H 2 "DATE (date)"
DATE is special case of the UNIX date.
Only the superuser has permission to change the system date, so an
error message is displayed if a date change is attempted by others.
The proposed new date is printed, however.
.H 2 "DEL (del)"
This is almost the same as the UNIX rm command. The difference is
a ``safety~net'' to catch deletion of multiple files.
.H 2 "DIR (dir)"
Directory listings are done by ls with various flags.
All DOS flags are supported, but System V, Release 2 is required.
.H 2 "DISKCOMP (diskcomp)"
Comparing whole disks (file structures) in UNIX is usually meaningless,
so DISKCOMP compares directories.
The /L and /8 flags are meaningless to UNIX, and are ignored.
.H 2 "DISKCOPY (diskcopy)"
Copying whole disks (file structures) in UNIX is usually meaningless,
so DISKCOPY copies directories.
The target directory must exist beforehand.
.H 2 "ECHO (echo)"
ECHO is identical to the UNIX echo, except when called in a .bat file with the
single argument ``on'' or ``off'', which toggles the x option of set.
.H 2 "EDLIN (edlin)"
Technically, EDLIN is not a DOS command, but an application program.
Note that it is documented in an appendix of the DOS manual.
The EDLIN line editor is the functional equivalent of ed, but the
similarity does not stop there. See Table 1 for a command-by-command comparison.
The command line editing function keys do not work within EDLIN.
.DF
.TB "Editor Commands"
.SP
.TS
box tab(;);
lBlBlB
l1wl2wl.
Function;EDLIN;ed;
=
Append~Lines;[lines]A;r filename;
~~~from~disk;;
_
Append Lines;;[line]a;
_
Copy Lines;[line][,line],line,[cnt]C;[line][,line]t[line];
_
Delete Lines;[line][,line]D;[line][,line]d;
_
Edit Line;[line];[line];
_
Exit~Editor;E;w;
~~~(save);;q;
_
Insert Lines;[line]I;[line]i;
_
End Insertion;CTRL-Z;. (column 1);
_
Help Mode;;H;
_
Print Lines;[line][,line]L;[line][,line]p;
_
Move Lines;[line][,line],lineM;[line][,line]m[line]
_
Page;[line][,line]P;[line,line+22]p;
_
Quit~Editor;Q;Q;
~~~(no~save);;
_
.T&
lls.
Substitute;[line][,line][?]Rstring1CTRL-Zstring2;
.T&
lrs.
~~~Text;[line][,line]s/string1/string2[/g];
_
.T&
l1wl2wl.
Search Text;[line][,line]S[string];/string;
_
Transfer Lines;[line]Tfilename;[line]r filename;
_
Write Lines;[n]W;[line][,line]w;
.TE
.DE
.H 2 "ERASE (erase)"
This is a synonym for DEL.
.H 2 "EXE2BIN (exe2bin)"
The UNIX analog is strip.
.H 2 "EXIT (exit)"
The UNIX exit is identical in function.
.H 2 "FC (fc)"
File comparisons are done by diff, after preprocessing by
tr in some cases. All DOS flags are supported.
.H 2 "FDISK (fdisk)"
FDISK provides an environment, and as such has no command syntax.
The equivalent UNIX function is available (to superusers) in mkfs.
.H 2 "FIND (find)"
FIND is a special case of the UNIX grep.
.H 2 "FOR"
The DOS FOR command (note that ``for'' is still the UNIX command, since
it is a keyword that cannot be over-written or aliased) works as
documented, except that the parentheses must be square (i.e., [...]),
or protected with backslashes (i.e., \\(...\\)).
The ``variable'' in the FOR command is really a dummy variable, and should 
be denoted, as in DOS, by a percent sign.
For example,
.DS
.in +.8i
FOR %i in [ a b c ] do echo %i $xyz
.in
.DE
.H 2 "FORMAT (format)"
As with DOS, FORMAT formats floppy disks.
.H 2 "GOTO (goto)"
GOTO is a DOS batch command that has no direct UNIX analog.
The branching of GOTO is done using the UNIX case command.
A batch compiler has been provided, that, when invoked from within
dsh, will translate a DOS batch file (i.e., .bat file)
into the corresponding UNIX shell script.  See the section on
batch files below.
.H 2 "GRAPHICS (graphics)"
GRAPHICS dumps the screen to a printer, exactly as in DOS.
The mc0 entry from the TERMINFO database is used, since this is terminal
dependent.
.H 2 "IF"
Except for the lack of a lower case version, IF works exactly the same as
the DOS version.
.H 2 "MD (md)"
MD is a synonym for MKDIR (below).
.H 2 "MKDIR (mkdir)"
MKDIR is identical to the UNIX mkdir.
.H 2 "MODE (mode)"
The functions of MODE are provided by stty, among other commands.
Because the UNIX environment is multiuser, these functions are
usually defined once and for all by the superuser, with careful
reference to the appropriate manual.
The characteristics of the available devices are then made known to
all users, who choose, rather than define, their devices.
Under dsh, MODE does nothing.
.H 2 "MORE (more)"
Identical to the UNIX pg with a specific set of options.
.H 2 "PATH (path)"
PATH is a function to set the UNIX PATH variable ($PATH), or print it
if there are no arguments.
As in DOS,
the current directory is always searched first, no matter what PATH is
defined to be.
If semicolons are used to separate segments of the PATH, they must be
entered with a backslash (i.e., \e;), since the semicolon is the UNIX
command terminator that permits multiple commands per line.
Colons may be used in place of semicolons in the PATH command line,
if desired.
.H 2 "PAUSE (pause)"
PAUSE stops, issues a prompt, and waits for input (which it ignores),
exactly as in DOS.
.H 2 "PRINT (print)"
PRINT is the DOS printer spooler, the analog of lp.
UNIX has true concurrency, so the /T (terminate), /C (cancel), and /P
(resume printing) flags are ignored.
PRINT returns a message containing a job number (called a ``request id'').
Type ``cancel'' followed by the job number to halt the printing.
.P
Since there are typically multiple printers or multiple printer
options available on a given UNIX installation, a provision has been
made for customizing the PRINT command.
The DOSPRINT variable is defined at installation.
Users may re-define this variable, either in the UNIX profile,
autoexec, or from the keyboard, to be the UNIX command sequence needed to
spool print jobs to the desired local printer.
Typically this command would be something like
.DS
.in +.8i
SET DOSPRINT = lp -d x1
.in
.DE
in the autoexec file
to send print output to printer x1.
See the section on Initialization below.
.H 2 "PROMPT (prompt)"
PROMPT defines the prompt string. By default, the DOS prompt is the drive
(i.e., file structure) name.
In UNIX, the file structures are unified from the user's point of view, so
a prompt showing the top directory only is not informative.
The default prompt string for dsh, therefore, is the home directory name
if the user is in the home
directory, the subdirectory path if below the home directory, and the
complete path otherwise.
When in the home directory, or outside it, a complete path name
(``fully qualified'' in the jargon) starting with a ``/'' is displayed.
When below the home directory, only the part of the path below
the home directory (no leading ``/'') is displayed.
Many UNIX users prefer the shorter prompt that corresponds to ``PROMPT~$p$g'',
showing only the current directory name.
.P
The prompt is under the user's complete control,
and all the DOS ``$'' mnemonics have been implemented.
In addition, the DOS reverse video toggles ($e[7m and $e]m) are intercepted
and translated into the appropriate sequences.
Unlike DOS, however, other variables
can be inserted in the prompt string
by merely adding them to the list.
.H 2 "RD (rd)"
RD is a synonym for RMDIR (below).
.H 2 "RECOVER (recover)"
There is no direct UNIX analog.
Recovery of the usable pieces of files is done by fsck automatically
(see  also CHKDSK).
.H 2 "REM (rem)"
Remark is provided by ``#'' in UNIX.
.H 2 "REN (ren)"
Renaming is done by mv with some preliminary processing to
honor wild-cards in the DOS style.
.H 2 "RENAME (rename)"
A synonym for REN (above).
.H 2 "RESTORE (restore)"
The inverse of BACKUP, RESTORE also uses cpio.
All flags work as defined.
.H 2 "RMDIR"
The RMDIR command is identical to the UNIX command of the same name.
.H 2 "SET"
The SET command defines and exports shell variables, exactly the same in
DOS and UNIX.
.H 2 "SHIFT (shift)"
Identical in both DOS and UNIX.
.H 2 "SORT (sort)"
The DOS SORT command is a special case of the UNIX sort.
.H 2 "SYS (sys)"
SYS copies the hidden system files in DOS. 
No UNIX analog is needed.
.H 2 "TIME"
TIME is a special case of the UNIX date command.
Only the superuser has permission to change the system time, so an
error message is displayed if a time change is attempted by others.
The proposed new time is printed, however.
.H 2 "TREE (tree)"
TREE is a special case of ls. 
All options are functional.
.H 2 "TYPE (type)"
TYPE is equivalent to the UNIX cat.
.H 2 "VER (ver)"
VER displays the UNIX operating system Version number.
.H 2 "VERIFY (verify)"
No UNIX analog is needed.
UNIX verifies copies automatically, returning ``Bad~copy~...'' when one is
discovered.
.H 2 "VOL (vol)"
The UNIX command ``df'' reports the name and total free space for each
file system.
.H 1 "Batch Processing Commands"
All the DOS batch processing commands are available in dsh.
Batch files (command_name.bat or command_name.BAT)
must be converted to executable shell procedures.
The command 
.DS C
batc command_name
.DE
will translate the DOS batch file command_name.bat
or command_name.BAT into the corresponding
UNIX shell script, which will be stored in command_name (i.e., the ``.bat''
is stripped) in the same directory.
The command
.DS C
command_name arg1 arg2 ..
.DE
will then work in exactly the same way under dsh as under DOS.
The command
.DS C
batcg command_name arg1 arg2 ..
.DE
will convert the batch file and then execute it.
.P
Alternatively, the command 
.DS C
make command_name
.DE
uses the UNIX make facility to translate the
DOS batch file command_name.bat
or command_name.BAT into the corresponding
UNIX shell script, if the batch file has been updated more
recently than the shell script.
.P
The processing performed on DOS batch files includes:
.AL 1
.LI
conversion of GOTO statements into a UNIX case construct;
.LI
translation of break, for, if, set and time to upper case;
.LI
conversion of parentheses in FOR statements to square brackets;
.LI
conversion of DOS variables (%name%) and parameters (%0, %1, .., %9)
to their UNIX counterparts (and of %% to %);
.LI
conversion of backslashes to slashes.
.LE
.ne 5
.H 1 Miscellaneous
.H 2 "Reserved file names and extensions"
DOS reserves six filenames (AUX, CON, PRN, COM1, COM2
and NUL) for the auxiliary
device, console, printer, communications ports 1 and 2, and trash.
These cannot be hardwired in UNIX, since they could be different
for each user.
Therefore, they have been converted to variables ($AUX, $CON, $COM1, $COM2,
$PRN, and $NUL) and initialized by dsh (to /dev/tty for $CON
and /dev/null for the others).
$AUX  $COM1, $COM2 and $PRN can be redefined by the user.
For example,
.DS C
SET PRN = /dev/lp1
.DE
is a typical definition if a printer is attached.
A typical usage would then be
.DS C
TYPE file1 >$PRN
.DE
.P
UNIX makes use of file extensions (e.g., .c for C program source, .o
for object code, etc.) of arbitrary length, not just  the three
characters of DOS.
The .bat and .BAT extensions are recognized by the UNIX make
command, when invoked from the dsh environment, as DOS code
to be compiled to a dsh command file.
Once compiled, typing the filename and any arguments will result
in execution, exactly analogous to DOS.
The .exe and .com extensions are meaningless to UNIX.
.H 2 Initialization
If dsh finds an ``autoexec'' file in the user's home directory,
it will execute it when it first starts.
This is analogous to DOS execution of an ``autoexec.bat'' file, but
dsh requires the compilation to ``autoexec''.
In addition, dsh will define CTRL-C to be the interrupt and line-delete
sequence when it initializes.
.H 2 "Function Keys"
DOS initializes the first five function keys (F1-F5) to permit editing
of the previous command.
A similar capability exists in dsh, but the keys must be loaded by the
user.
On most terminals, this can be done once, and then remembered or down-loaded
as needed.
The key definitions in Table 2 are recommended,
since the first five keys closely match the DOS definitions.
.DF
.TB "Function Key Definitions"
.SP
.TS
box tab(;);
lBlBlBlB
l1wl2wc1wl.
Key;Label;Definition;Function;
_
F1;T{
.ll .75i
.fi
NEXT CHAR
T};^F;T{
.ll 1.85i
.fi
Move
cursor
to next position
T};
_
F2;T{
.ll .75i
.fi
FIND CHAR
T};^];T{
.ll 1.85i
.fi
Find next
instance of a
given character
T};
_
F3;T{
.ll .75i
.fi
TO END OF LINE
T};^E;T{
.ll 1.85i
.fi
Move cursor
to end of line
T};
_
F4;T{
.ll .75i
.fi
DELETE CHAR
T};^D;T{
.ll 1.85i
.fi
Delete character
at cursor
T};
_
F5;REFRESH;^A\f2esc\f1-p^L;T{
.ll 1.85i
.fi
Refresh the
command line display
T};
_
F6;T{
.ll .75i
.fi
EDIT PREV CMD
T};^P^A;T{
.ll 1.85i
.fi
Edit previous
command
T};
_
F7;T{
.ll .75i
.fi
DELETE TO EOL
T};^K;T{
.ll 1.85i
.fi
Delete all
characters to the
end of the line
T};
_
F8;T{
.ll .75i
.fi
PREV CHAR
T};^B;T{
.ll 1.85i
.fi
Move cursor
to previous
character
T};
.TE
.DE
In the table, ^X represents CTRL and key X (simultaneously),
and \f2esc\f1-X represents escape followed by key X.
.P
With these function key definitions, any previously issued command
may be recalled (by pushing the F6 button multiple times) and edited.
Those familiar with UNIX will recognize the function key definitions
as emacs editor commands, and indeed, most of the emacs editor is
available to process the command history.
The emacs commands can be given directly from the keyboard, if desired.
One emacs command that is useful, and can be used with the function keys,
is \f2esc\f1-number.
When an \f2esc\f1-number is followed by a function key, the effect of the
function key is multiplied by the number.
For example, \f2esc\f1-10 followed by F6 retrieves the tenth previous command.
.P
The command editing is not completely identical to DOS, but is similar,
easy to use, and more powerful.
.H 2 Installation
The dsh commands should be saved in a file not customarily searched
by vanilla UNIX users, since some dsh commands overwrite UNIX commands
with the same name.
The dsh shell script itself should be copied to a directory that is searched,
so that it will become available for execution.
The installation procedure has been mechanized to the greatest extent
possible.
After moving all source files to the directory where they are to be
kept, and changing to that directory, type
.DS CB
dsh_install dirname printer commands
.DE
where dirname is the name of the directory to be searched for dsh
(typically \f3NOT\f1 the directory containing the source), and the rest
of the command line is the UNIX command to be used as the default printer
command.
Be sure you have write permission for dirname.
The printer commands are optional, and will default to ``lp''.
For example,
.DS C
dsh_install /usr/lbin lp -d x10
.DE
will install the dsh command in /usr/lbin, and spool user's print requests to
destination x10 via the lp command.
