Whenever you type something at the command line and press the Enter key, or include a command in a batch file, you pass a command to TCC, which must determine how to execute it. If you understand the general process that is used, you will be able to make the best use of the commands. Understanding these steps can be especially helpful when working with complex aliases or batch file commands.
TCC goes through several steps when parsing a command line. Before it starts, it writes the entire command line (which may contain multiple commands) to the history log file if history logging has been enabled (with the LOG /H command) and the command did not come from a batch file. The first command is then isolated for processing. The following steps outline the basic processing required for each command. During that processing, additional parsing tasks may be triggered as noted and some steps may be repeated multiple times.
TCC begins by dividing the command into a command name and a command tail. The command name is the first word in the command, and the tail is everything that follows the command name. For example, in the command line
dir *.txt /2/p/v
The command name is dir, and the command tail is "*.txt /2/p/v". In some instances, the parser will be able to understand incorrect syntax such as dir/w, but there should always be at least one space between the command name and its parameters.
Next, TCC tries to match the command name against its list of aliases. If it finds a match between the command name and one of the aliases you've defined, it replaces the command name with the contents of the alias.
If the alias included parameters (%1, %2, etc.), the parameter values are filled in from the text on the command line, and any parameters used in this process are removed from the command line. The process of replacing a command name that refers to an alias with the contents of the alias, and filling in the alias parameters, is called alias expansion.
This expansion of an alias creates a new command name: the first word of the alias. This new command name is again tested against the list of aliases, and if a match is found the contents of the new alias is expanded just like the first alias. This process, called nested alias expansion, continues until the command name no longer refers to an alias.
The next step is to locate any batch file parameters, environment variables, internal variables, or variable functions in the command, and replace each one with its value (see "Environment: Variables and Functions").
The variable expansion process is modified for certain internal commands, such as EXCEPT, IF, and GLOBAL. These commands are always followed by another command, so variable expansion takes place separately for the original command and the command that follows it.
Once it has finished variable expansion, TCC next tries to match the resulting command name with its list of plugin commands or internal commands. If it is unsuccessful, it knows that it will have to search for a batch file or external program to execute your command.
You can specify a particular plugin to execute by prefixing the function / variable / command name with the plugin name and a $. For example:
When all of the aliases and environment variables have been expanded, TCC will echo the complete command to the screen (if command line echo has been enabled) and write it to the log file (if command logging has been turned on).
Before it can actually execute your command, TCC must scan the command tail to see if it includes redirection or piping. If so, the proper internal switches are set to send output to an alternate device or to a file instead of to the screen. A second process is started at this point, if necessary, to receive any piped output.
At this stage, any remaining Escape Characters are processed. However, this might also already have taken place inside some of the variable functions (such as @IF) that are likely to pass escaped strings in their parameters. If you are referencing one of those in an ECHO or similar command, you need to escape twice ("^^") or use SETDOS /X to avoid premature evaluation. Carefully test those situations to make sure the results are as you intended.
Finally, it is time to execute the command. TCC will first look for a matching plugin command name; if it doesn't exist then it tries to match an internal command. Otherwise, TCC searches for an executable (.EXE) file, a batch file, or a file with an executable extension that matches the command name (see the detailed description of this search in Executable Files and File Searches).
If the first argument on a command line is in the format "env_var=value command options" (and env_var=value doesn't match an external command) then TCC will set the specified environment variable to the value, execute the command, and then remove the variable.
Once the internal command or external program has terminated, TCC saves the result or exit code that the command generated, cleans up any redirection that you specified, and then returns to the original command line to retrieve the next command. When all of the commands in a command line are finished, the next line is read from the current batch file, or if no batch file is active, the prompt is displayed.
Note: You can disable and reenable several parts of command parsing (for example alias expansion, variable expansion, and redirection) with the SETDOS /X command.