There are two types of commands: internal commands and external commands. External commands are executable files and command script files. Internal commands are coded into the command interpreter itself, and are thus known as built-in commands.
When an individual command is executed, it is checked against the list of known built-in commands. If it matches, the built-in command is executed in the command interpreter process itself. This allows built-in commands to modify parts of the state of the command interpreter process itself that child processes are not allowed to modify by the operating system. For example, child processes are not allowed to modify a parent process' environment, so the SET and UNSET commands are both internal commands.
If a command is not recognised as an internal command, and its name contains an explicit drive or directory, then that is the name of the file that is executed.
Otherwise, the command interpreter uses the PATH and PATHEXT environment variables to locate the file containing the external command to execute. In each directory on the list of directories specified by the PATH environment variable, the command interpreter appends in turn each extension on the list of extensions specified by the PATHEXT environment variable.
The PATH and PATHEXT environment variables provide full control over the way in which an external command is located. Modifying PATH controls the order in which directories are searched. Modifying PATHEXT controls the precedence of various extensions, allowing CMD files to be executed in preference to EXE files, for example.
When a file or directory name is found, it is executed. If it is a directory name, the command interpreter changes to that directory. If it is a file name, the command interpreter first attempts to execute it as if it were an ordinary executable program. If that fails, the command interpreter assumes that it is a script.
If the first two characters of a command script file are slash and asterisk, it is executed as a REXX script. Otherwise it is treated as a sequence of command lines that are read and executed sequentially.
If the script is not a REXX script, the first 8 characters of a command script are the string "EXTPROC" followed by a whitespace character, and EXTPROC is a recognised built-in command, the echo flag is turned off for the execution of the script.