The command line is one of the central concepts of batch programming. It is used to describe command behaviours and to parse scripts.
The conventions presented here are used a Dos9 standard.
Commands and Blocks
The is two kinds of structures within batch scripts. The first are commands, the most important part of code and the second are blocks that form a group of commands.
Commands are the simplest structure of batch programming. Every action is done using a command. Commands are lines (or a part of line, if conditonnal operators are used), that denote an action to be done. Typically, commands are described using the following syntax :
COMMAND mandatory_argument [optional_argument] [choice1 | choice2]
COMMAND is the name of the command.
madatory_argument is an argument that must be specified for the command to run properly. It can either be a word or a group of words surrounded by quotes (' or ") or with spaces escaped with ^. Thus, there is several ways of passing an argument:
COMMANDE "foo bar"
COMMANDE 'foo bar'
COMMANDE foo^ bar
All of theses syntaxes are valid and can be used interchangeably. Note that no conditional operator will be interpreted within quotes.
Optional_argument is an argument that is not required by the command and is optional. These arguments only affect the behaviours of the command. Two arguments can be simultaneously optional is specified as:
COMMAND [arg1 arg2]
In this case, arg1 and arg2 have to be both specified for the command to be executed. Obviously, when specifying optional parameters you should not use the square brackets ([ and ]), theses are just a way to depict optionality.
[choice1|choice2] specify a choice that have to be made between choice1 and choice2. Usually, specifying one of them is not mandatory as square brackets depict optionality. Some can consider this syntax ambiguous and depict the necessity of making a choice not using brackets, like:
No Dos9 command is supposed to use this syntax as it not required for well designed command to require the user to make a mandatory
Command blocs are groups of commands that need to be executed together. They are obtained by the use of parenthesis:
Conditional operators and redirections are not active within blocs by default, this means that neither |, ^, &, < nor > have to be escaped using ^ within blocs. However, if you set ../setlocal CMDLYCORRECT setting, then it will be possible to have theses symbols escaped.
Within a block, every command share the same output and input with other commands (unless if the output is redirected within the block). This enables grouped output as :
(ECHO first line
ECHO second line) > file
IF 1==1 (
ECHO une ligne
ECHO une autre ligne