AUTOEXEC.BAT in MS-DOS Secondary Shells
In MS-DOS 6.22, spawning a secondary command processor via
COMMAND.COM bypasses standard boot routines, meaning the
AUTOEXEC.BAT file plays no active role by default. This
article explains how secondary shells handle startup scripts, why
AUTOEXEC.BAT is ignored during standard subshell execution,
and the specific parameters that alter this behavior.
Default Secondary Shell Behavior
When an application drops to a DOS prompt or a user manually invokes
COMMAND.COM from the command line, MS-DOS launches a
secondary (child) shell. By design, this secondary shell does not parse
or execute AUTOEXEC.BAT.
The primary purpose of AUTOEXEC.BAT is system
initialization at boot time. Because TSR (Terminate-and-Stay-Resident)
programs, hardware drivers, and fundamental system configurations are
already loaded into memory by the primary shell, re-running
AUTOEXEC.BAT in a subshell could cause memory conflicts,
duplicate TSR instances, or system instability.
Environment Inheritance
Instead of running AUTOEXEC.BAT to configure the
workspace, a secondary shell inherits a copy of the parent shell's
current environment table. This environment includes existing variables
such as PATH, PROMPT, and
TEMP.
Any changes made to environment variables within the secondary shell
only affect that specific subshell instance. When the user types
EXIT to terminate the secondary shell, control returns to
the parent program or primary shell, and any environment modifications
made in the child shell are lost.
Exceptions Using Command-Line Switches
While AUTOEXEC.BAT is ignored during standard secondary
shell creation, specific command-line switches modify how
COMMAND.COM handles startup files:
- The
/P(Permanent) Switch: When invoked withCOMMAND /P, the shell is made permanent and cannot be closed using theEXITcommand. This switch forcesCOMMAND.COMto processAUTOEXEC.BATlocated in the root directory. This mechanism is primarily utilized in theCONFIG.SYSfile via theSHELL=command to establish the primary shell during boot, but runningCOMMAND /Pmanually will also trigger the execution ofAUTOEXEC.BAT. - The
/CSwitch: To execute a specific batch file or command immediately upon opening a secondary shell, the/Cparameter is used (for example,COMMAND /C SCRIPT.BAT). The shell runs the specified instructions and immediately terminates back to the parent environment, providing a targeted alternative to runningAUTOEXEC.BAT.