DOS stores a default directory for each drive. When a path is
specified with a drive specification only, such as
The drive is a single letter from
The remaining part of a path consists of similiar components
delimited by a single backslash
Note: The term filename is not limited to files
in the usual sense, but may apply to any name visible in a directory,
such as subdirectories and volume labels, as well.
To ease the way to enter a path the user may specify a relative path, rather than an absolute one. In such path one or more components may be missing:
Examples, assume the current directories of
Drive | Current Directory |
C: | |
D: |
Path specifications that do not conform to above mentioned format lead to various different behaviour of the various programs, because there is no standard to scan, parse and interprete such patterns. Problems include:
Note: The special directories
Some commands do accept long option names, where a complete word
identifies the option rather than a single character, e.g.
Some option may be used in conjunction with an argument. The argument
is appended to the option with one colon "
Multiple options without argument maybe merged together
as a single option with embedded slashes, e.g.
An option with argument may be the last one of such merged options.
Options without arguments enable or disable certain features. Therefore,
those options are sometimes called boolean options or flags.
Boolean options may be prefixed by a minus "
Without user invention a boolean option is disabled by default.
However, some commands allow the user to change the default settings of
certain options, e.g. COPY and DIR.
If the input stream is redirected to a file or device, instead of polling the keyboard and request the user to interactively enter characters via the keyboard, those characters are read from the file or device. Usually these programs terminate when the file has been read wholely.
If the output stream is redirected to a file or device, instead of issuing the information onto screen, it is dumped into the file or device. Per convention each program has two output streams: one (called standard output) to issue normal information and one (called standard error output) for error messages the user should not miss.
Redirections are specified on command line and effect exactly that
command invoked herein, regardless if the command is an external or
internal one, an alias or batch script. The utter exception is the FOR
command, which requires that the redirection is to apply to the command
specified behind the DO keyword rather than FOR itself.
If more than one redirection is specified on the command line and
they effect the same stream (input, output, or error), the rightmost one
superceed any previous one.
Redirections are syntactically specified like this:
EBNF: operator target
EBNF: operator ::= '<' | '>' [ '>' ]
EBNF: target ::= file | device
Although it is not relevant where the redirections are placed on the
command line, it is common praxis to place them at the end of it.
The
Operator | Redirection |
---|---|
Input stream | |
Output stream; target file is overwritten | |
Output stream; output is appended to target, if it already exists |
Another form of redirection is piping. Hereby, the output stream
of one command is connected to the input stream of another command. Pipes can combine
any number of commands this way. Because DOS is no multitasking system, pipes are
simulated by spawning the first command with an output redirection capturing the
issued information into a temporary file and then the second command with an input
redirection from that very same temporary file, on completation of the second
command the temporary file is deleted.
EXAMPLES:
EXAMPLE: 1
CMD: cmd1 | cmd2 | cmd3
Consider the batch file FreeCOM supports the standard DOS wildcards as supported by the DOS
kernel itself:
Examples:
Warning: There are common mistakes about wildcards,
as DOS has less functional wildcards than other systems, in particular:
By default, before executing a line, it is displayed onto the screen,
in order to prevent this, one can turn off this feature with the ECHO command
or prefix each line with the Ad sign ( Lines starting with a colon ( When the shell reaches the end of the file, the batch processing terminates.
The errorlevel of the last spawned external command remains unchanged.
Because the shell closes the batch script and re-opens it each time a
command, for both internal and external ones, is invoked, one can savely
replace floppy disks during a batch processing, e.g.:
When a batch file is invoked within another batch file, the previous ones
does not proceed once the called one terminates, regardless of the
nesting level; this is called chaining, one chains to another
program and does not intend to come back. To have a batch script behave
like an external program in this regard, it must be invoke via the
CALL command, e.g.:
Which is similiar to this sequence:
CMD: cmd1 >%TEMP%\t1
CMD: cmd2 <%TEMP%\t1 >%TEMP%\t2
CMD: DEL %TEMP%\t1
CMD: cmd3 <%TEMP%\t2
CMD: DEL %TEMP%\t2
EXAMPLE: 2
The first and last command can have an input or output redirection
respectively, like so:
CMD: cmd1 | cmd2 | cmd3
Which is similiar to this sequence:
CMD: cmd1 >%TEMP%\t1
CMD: cmd1 |& cmd2 | cmd3
Which is similiar to this sequence:
CMD: cmd1 >&%TEMP%\t1
CMD: cmd2 <%TEMP%\t1 >%TEMP%\t2
CMD: DEL %TEMP%\t1
CMD: cmd3 <%TEMP%\t2
CMD: DEL %TEMP%\t2
Here only the error messages of Nested redirections
Batch scripts or when external programs invoke other programs or another shell,
redirections may be nested, e.g.:
@ECHO OFF
ECHO 1
ECHO 2 >out_2
ECHO 3
which is invoked via:
CMD: BATCH >out_1
When the script
Because the second ECHO command has its own output redirection, its
output is redirected into the file
What causes that the output of the third ECHO command is redirected
into
Wildcards
DOS accepts certain placeholders instead of files, so you can specify
one or more files with the same wildcard pattern. In opposite to other
systems each program expands wildcards individually instead of let the
shell do this; however, the shell must epxand wildcards for its internal
commands.
Wildcard Meaning
Any remaining body, except a dot (
Any character, except the dos (
Wildcards are allowed in the last portion of a qualified path, that means
behind the last backslash (
Wildcards match either before or behind the dot delimiting the
filename and its extension.
Whether or not directories or volume lables or hidden and system
files do match a pattern depends on the command expanding it.
Letters match case-insensitively.
Pattern Meaning
Any file in the current directory
Any file in the current
working directory of drive C:
Any file without an extension.
Some commands, such as DIR, interprete a single
Any file, which first character is
an
same as above
same as above
same as above
Any file, which first character is
an
All files, which first four characters
are
Any perl file in the directory
Batch Scripts
The shell lets to automate simple tasks by writing batch scripts.
These are plain text files with one command is written at one line.
Any command, both internal and external ones, can be used in batch
scripts, along with redirections,
pipes, environment variable
substitions a.s.o. The script is performed line-by-line.
CMD: ECHO This line is displayed
CMD: @ECHO This line is NOT displayed
Commonly batch scripts start with the line:
CMD: @ECHO OFF
in order to turn off to echo each line furtherly in the script
processing and to suppress to echo the line itself, too.
CMD: @ECHO OFF
CMD: IF "%1"=="" GOTO useage
CMD: ECHO argument1=%1
CMD: ECHO argument2=%2
CMD: ECHO argument3=%3
CMD: GOTO ende
CMD: :useage
CMD: ECHO Useage: %0 {arguments}...
CMD: :ende
If the shell hits a line starting with a colon, it is silently skipped; not
even redirections are evaluated in opposite to the REM command.
CMD: @ECHO OFF
CMD: ECHO Copying disk1
CMD: COPY files\*.* C:%1
CMD: :disk2
CMD: PAUSE Insert disk #2, then hit ENTER
CMD: IF NOT EXIST disk2 GOTO disk2
CMD: ECHO Copying disk2
CMD: COPY files\*.* C:%1
CMD: :disk3
CMD: PAUSE Insert disk #3, then hit ENTER
CMD: IF NOT EXIST disk2 GOTO disk3
CMD: ECHO Copying disk3
CMD: COPY files\*.* C:%1
CMD: ECHO Copying done.
CMD: @ECHO OFF
CMD: ECHO %0 - line 2
CMD: CALL batch2
CMD: ECHO %0 - line 4
and
CMD: ECHO %0 - line 1