Environment Variables and Functions
The environment is a collection of information about your computer that
every program receives. Each entry in the environment consists of a
variable name, followed by an equal sign and a string of text. You can
automatically substitute the text for the variable name in any command.
To create the substitution, include a percent sign [%] and a variable
name on the command line or in an alias or batch file.
The following environment variables have special meanings in CMD.EXE:
CDPATH
CMDLINE
COLORDIR
COMSPEC
FILECOMPLETION
PATH
PATHEXT
PROMPT
CMD.EXE also supports two special types of variables. Internal variables
are similar to environment variables, but are stored internally within
CMD.EXE, and are not visible in the environment. They provide
information about your system for use in batch files and aliases.
Variable functions are referenced like environment variables, but
perform additional functions like file handling, string manipulation and
arithmetic calculations.
In CMD.EXE the size of the environment is set automatically, and
increased as needed when you add variables.
The SET command is used to create environment variables. For example, you
can create a variable named BACKUP like this:
[c:\] set BACKUP=*.bak;*.bk!;*.bk
If you then type
[c:\] del %BACKUP
it is equivalent to the following command:
del *.bak;*.bk!;*.bk
Environment variable names may contain any alphabetic or numeric
characters, the underscore character [_], and the dollar sign [$]. You
can force acceptance of other characters by including the full variable
name in square brackets, like this: %[AB##2]. You can also "nest"
environment variables using square brackets. For example %[%var1] means
"the contents of the variable whose name is stored in VAR1". A variable
referenced with this technique cannot contain more than 255 characters of
information. Nested variable expansion can be disabled with the SETDOS
/X command.
Environment variables may contain alias names. The command processor
will substitute the variable value for the name, then check for any alias
name which may have been included within the variable's value. For
example, the following commands would generate a 2-column directory of
the .TXT files:
[c:\] alias d2 dir /2
[c:\] set cmd=d2
[c:\] %cmd *.txt
The trailing percent sign that was traditionally required for environment
variable names is not usually required in CMD.EXE, which accept any
character that cannot be part of a variable name (including a space) as
the terminator. However, the trailing percent can be used to maintain
compatibility.
The trailing percent sign is needed if you want to join two variable
values. The following examples show the possible interactions between
variables and literal strings. First, create two environment variables
called ONE and TWO this way:
[c:\] set ONE=abcd
[c:\] set TWO=efgh
Now the following combinations produce the output text shown:
%ONE%TWO abcdTWO ("%ONE%" + "TWO")
%ONE%TWO% abcdTWO ("%ONE%" + "TWO%")
%ONE%%TWO abcdefgh ("%ONE%" + "%TWO")
%ONE%%TWO% abcdefgh ("%ONE%" + "%TWO%")
%ONE%[TWO] abcd[TWO] ("%ONE%" + "[TWO]")
%ONE%[TWO]% abcd[TWO] ("%ONE%" + "[TWO]%")
%[ONE]%TWO abcdefgh ("%[ONE]" + "%TWO")
%[ONE]%TWO% abcdefgh ("%[ONE]" + "%TWO%")
If you want to pass a percent sign to a command, or a string which
includes a percent sign, you must use two percent signs in a row.
Otherwise, the single percent sign will be seen as the beginning of a
variable name and will not be passed on to the command. For example, to
display the string "We're with you 100%" you would use the command:
echo We're with you 100%%
You can also use back quotes around the text, rather than a double
percent sign. See Argument Quoting for details.
Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs