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 with COMMAND /P, the shell is made permanent and cannot be closed using the EXIT command. This switch forces COMMAND.COM to process AUTOEXEC.BAT located in the root directory. This mechanism is primarily utilized in the CONFIG.SYS file via the SHELL= command to establish the primary shell during boot, but running COMMAND /P manually will also trigger the execution of AUTOEXEC.BAT.
  • The /C Switch: To execute a specific batch file or command immediately upon opening a secondary shell, the /C parameter 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 running AUTOEXEC.BAT.