Windows Environment Variables Help. All commands in alphabetical order


    Team SETLOCAL used to temporarily change the values ​​of environment variables in batch files Windows. Environment changes made after executing the SETLOCAL command are local to the current batch file. To restore their previous values, you must issue the ENDLOCAL command. When the end of the batch file is reached, the ENDLOCAL command is automatically executed for all valid SETLOCAL commands issued in that batch file and the values ​​of all environment variables are restored to the state before the SETLOCAL command was executed.

Command line format:

SETLOCAL | ENABLEDELAYEDEXPANSION | DISABLEDELAYEDEXPANSION

Changing the SETLOCAL command when enabling extended command processing:

The SETLOCAL command accepts optional arguments: ENABLEEXTENSIONS or DISABLEEXTENSIONS. This allows you to enable or disable advanced command processing before the command is executed. See CMD /? for a detailed explanation. ENABLEDELAYEDEXPANSION / DISABLEDELAYEDEXPANSION Enables or disables delayed environment variable expansion. See SET /? for a detailed explanation. These changes are in effect until the ENDLOCAL command is matched, regardless of the initial state before the SETLOCAL command was called.

If the SETLOCAL command is called with an argument, it sets the error code ERRORLEVEL. If one of the two valid arguments is given, the error code will be zero, otherwise 1 will be returned. This property can be used in batch files to determine whether extended command processing is available, for example:

VERIFY OTHER 2>nul
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 echo Unable to enable advanced processing

This group of commands works because in previous versions The CMD.EXE SETLOCAL command does not set the value to ERRORLEVEL. A VERIFY command with an invalid argument is required to set ERRORLEVEL to a non-zero value.

When using environment variables in command files, there is a certain limitation associated with the fact that the assigned value remains unchanged when it is modified within a group of commands specified by parentheses, for example in commands IF or FOR. To bypass this limitation use the command processor launch with the /V:ON parameter and instead of percent signs to obtain the received value variable, exclamation marks are used. In addition, it is possible to use the standard shell launch, but with local inclusion this mode command:

The difference in the results of using variable values ​​is quite clearly demonstrated by the following batch file:


@ECHO OFF
set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "!VAR!" == "after" @echo With percent sign=%VAR% , With question mark=!VAR!

Team set VAR=after executed inside a subroutine delimited by parentheses and, if the command is removed Setlocal EnableDelayedExpansion or not to use to get the value of a variable VAR exclamation marks, its value will remain the old one (what was set before entering the subroutine). A similar problem occurs when the value of a variable is changed within the command loop. FOR. For example, to get a list of files in the current directory, a batch file like this won't work:

set LIST=
for %%i in (*) do set LIST=%LIST% %%i
echo %LIST%

Variable value LIST will not be changed inside the loop. In order for this to happen, the batch file needs to be modified as follows:

Setlocal EnableDelayedExpansion
set LIST=
for %%i in (*) do set LIST=!LIST! %%i
echo %LIST%
Now, the value of the variable LIST inside a loop FOR will change, sequentially taking on the values ​​of file names separated by space ( set LIST=!LIST! %%i)

div.main (margin-left: 20pt; margin-right: 20pt)
Console Windows commands NT

Initially, many NT users do not take advantage of the capabilities that console commands provide, or do not fully use them.

In this material I would like to describe the main points of working with the console. Why, you ask, is this needed? Knowledge main commands allows you to automate work by using them in batch files, but when working with the network, many of them are irreplaceable. All of the above will apply mainly to Windows XP, but may well be applicable to other versions of NT (4, 2000), albeit with some restrictions.
NT is based on slightly different principles than Win9x. However, MS-DOS is also present, although only as a virtual machine(NT Virtual DOS Machine, NTVDM). In fact, this is a command line mode through which utilities and batch files are entered and executed.
The command line can be accessed through the Start menu/Programs/Accessories/Command Prompt.
The main command line interpreter in NT is cmd.exe, the main one is because there is also a standard MS-DOS command interpreter - command.com.
By running cmd.exe (via the menu or Start/Run/cmd.exe), we get a window in which you can work with the command line. Moreover, while already in the open command window, you can launch several more versions of cmd. To finish the job current version you can use the EXIT command.
There are two operating modes for cmd.exe - advanced and standard. Advanced mode works with the following commands:
DEL or ERASE; COLOR; CD or CHDIR; MD or MKDIR; PROMPT; PUSHD; POPD; SET; SETLOCAL; ENDLOCAL; IF; FOR; CALL; SHIFT; GOTO; START (the call has also been changed external teams); ASSOC; FTYPE.

CMD command
General command syntax:
CMD [command]
/C(/K) - Execute the specified command with/without subsequent termination.
Executes the specified command without later terminating.
/S - Change behavior after /C or /K (see below).
/Q - Disables the mode of outputting commands to the screen (ECHO).
/D - Disables execution of AutoRun commands from the registry (see below).
/A (/U) - Outputs the results of command execution in ANSI/UNICODE format.
/T:color - Select the text/background color (for more details, see the description of COLOR below).
/E:ON(/E:OFF) - Enable/disable command extensions (see below).
/F:ON(/F:OFF) - Allow/disable terminating characters for file and folder names (see below).
/V:ON(/V:OFF) - Enable/disable lazy expansion of environment variables using the "!" as a separator. For example, /V:ON allows the use of!var! as a runtime expansion of var. The var syntax is used to expand variables as you enter them, resulting in very different results internally FOR loop.
COLOR parameter Color attributes are specified as TWO hexadecimal digits - the first specifies the background color, and the second specifies the text color. Each digit can have the following meanings: 0=black, 1=blue, 2=green, 3=light blue, 4=red, 5=purple, 6=yellow, 7=white, 8=gray, 9=light blue, A =light green, B=light blue, C=light red, D=light purple, E=light yellow, F=bright white.
If no argument is specified, the command restores the original color selection as it was when CMD.EXE was run. This value is retrieved from the current text window, from the /T switch, or from the DefaultColor registry value.
The COLOR command returns an error code value of ERRORLEVEL 1 when attempting to call this command with the same text color and background color values.
Example: "COLOR fc" specifies light red text on a bright white background.
To specify multiple commands on one line, separate them with "&&" and enclose them in quotation marks. Also, for compatibility reasons, /X is the same as /E:ON, /Y is the same as /E:OFF, and /R is the same as /C. All other command line switches are ignored.
If the /C or /K switches are specified, then the rest of the command line after that switch is treated as the command line, and quotation marks (") are processed according to the following rules:
1. If all of the following conditions are met, then the quotation marks on the command line are preserved:
- the /S key is missing;
- there are exactly two quotation marks;
- there are no other special characters between them, such as: &<>()@^|;
- there are one or more spaces between them;
- the string enclosed in quotes is the name of the executable file.
2. Otherwise, the first character is checked and if it is a quote character, it is removed, the last quote character on the command line is also removed, and all text after that last quote character is retained.
If the /D switch is not specified on the command line, then when CMD.EXE is launched, the values ​​of the REG_SZ or REG_EXPAND_SZ variables are checked for the following sections of the system registry:
HKEY_LOCAL_MACHINESoftwareMicrosoftCommand ProcessorAutoRun
and/or
HKEY_CURRENT_USERSoftwareMicrosoftCommand ProcessorAutoRun
and if one or both of them are present, then they are executed first.
By default, enhanced command processing is enabled. To disable extended processing for a specific call, use the /E:OFF switch.
You can enable or disable extended command processing for all calls to CMD.EXE on this computer or for given user, using REGEDT32.EXE to set the REG_DWORD values ​​in system registry for sections:
HKEY_LOCAL_MACHINESoftwareMicrosoftCommand ProcessorEnableExtensions
and/or
HKEY_CURRENT_USERSoftwareMicrosoftCommand ProcessorEnableExtensions,
equal to 0x1 or 0x0. User settings override computer settings.
Command line switches, in turn, override registry settings.
Lazy environment variable expansion is not enabled by default. It can be enabled or disabled for a specific CMD.EXE call using the /V:ON or /V:OFF keys, or using REGEDT32.EXE by setting REG_DWORD values ​​in the system registry for sections:
HKEY_LOCAL_MACHINESoftwareMicrosoftCommand ProcessorDelayedExpansion
and/or
HKEY_CURRENT_USERSoftwareMicrosoftCommand ProcessorDelayedExpansion
equal to 0x1 or 0x0. User settings, as mentioned above, override computer settings, and command line keys, in turn, override registry settings.
If lazy environment variable expansion is enabled, the "!" (exclamation mark) can be used to replace the current value of an environment variable at runtime.
Enabling/disabling delayed expansion of environment variables for all calls to CMD.EXE on a given computer or for a given user is possible using REGEDT32.EXE with the REG_DWORD value in the system registry for the following keys:
HKEY_LOCAL_MACHINESoftwareMicrosoftCommand ProcessorCompletionChar,
HKEY_LOCAL_MACHINESoftwareMicrosoftCommand ProcessorPathCompletionChar
and/or
HKEY_CURRENT_USERSoftwareMicrosoftCommand ProcessorCompletionChar,
HKEY_CURRENT_USERSoftwareMicrosoftCommand ProcessorPathCompletionChar,
by setting their hexadecimal values ​​to the control character code used for the specific function (for example, 0x4 for Ctrl-D or 0x6 for Ctrl-F). Again, user settings override computer settings; Command line switches, in turn, override registry settings.
File and folder name completion is also not enabled by default. This can be corrected using the /F:ON or /F:OFF switches.
If completion is enabled using the /F:ON command line switch, then two control characters are used: Ctrl-D for folder names and Ctrl-F for file names. To disable a specific terminating character in the system registry, the special character code is used hexadecimal value space character (0x20).
Completion is called when one of these two special characters is entered. The completion function takes the path string to the left of the input point, appends a wildcard character to it if it doesn't have one, and then builds a list of paths that match the resulting definition. The first element of this list of matching paths is then printed. If the list is empty, then sound signal and nothing is output.
After that re-entry the same special character causes it to loop through all matching paths. Keystroke when entering a control character, allows you to view the list of paths in reverse order. If you change the output path and then enter the control character again, the saved list is cleared and built new list ways. The same thing happens if you switch from one completion symbol to another. The only difference when using the file terminator is that both the path and the file name are taken to build the matching list, whereas when using the folder terminator, only the path is used. When a folder terminator is used in one of the built-in folder manipulation commands (CD, MD, or RD), the folder terminator is always implied.
The terminator also works correctly with file names that contain spaces or other special characters, as long as the matching string is enclosed in quotation marks. Additionally, if you move the insertion point to the left and then use a trailing character within a line, the remaining text to the right of the insertion point will be discarded.
Special characters that require quotation marks:
<пробел>&(){}^=;!"+,`~

PROMT Team
Change the cmd.exe command line prompt.
PROMPT [text], where text is the new command line prompt. The invitation may include regular characters and the following codes:
$A - & (ampersand);
$B - | (vertical bar);
$C - ((left parenthesis);
$D - Current date;
$E - ESC ( ASCII character with code 27);
$F -) (right parenthesis);
$G - > (greater than sign);
$H - BACKSPACE (removing the previous character);
$L -< (знак "меньше");
$N - Current disk;
$P - Current disk and directory;
$Q - = (equal sign);
$S - (space);
$T - Current time;
$V - Number Windows versions XP;
$_ - Carriage return and line feed;
$$ - $ (dollar symbol).
When enhanced command processing is enabled, the PROMPT command supports the following additional formatting characters:
$+ - display the required number of plus (+) signs depending on the current depth of the PUSHD directory stack, one sign for each saved path;
$M - display full name remote disk associated with the name of the current drive, or an empty string if the current drive is not a network drive. For example, if drive E: is connected to network resource\ServerPrograms, then when using the PROMT $M$P$G command, the command line prompt format will be as follows: \ServerPrograms E:>.


Displaying, setting and deleting cmd.exe environment variables.

SET [variable=[string]]

variable The name of the environment variable.
line Character string, assigned to the specified variable.

Type SET without parameters to display the current environment variables.

Changing the SET command when enabling enhanced command processing:

If, when calling, you specify only the variable name without an equal sign and a value,
The SET command will print the values ​​of all variables whose names begin with
from the specified line. For example:

SET P

This command will print the values ​​of all variables whose names begin with "P".

If the variable name is not found in the current environment, the SET command returns
will set the error value to ERRORLEVEL 1.

The SET command does not allow an equal sign in the name
environment variable.

The SET command supports two additional switches:

SET /A expression
SET /P variable=

The /A switch indicates that the string to the right of the equals sign is numeric
expression whose value is calculated. The expression handler is very
is simple and supports the following operations, listed in descending order
priority:


When using any logical or binary operators, you must
enclose the expression string in quotes. Any non-numeric strings in the expression
are treated as names of environment variables whose values ​​are converted
V numeric form before use. If a variable with specified name
is not defined in the system, a null value is substituted. This
allows you to perform arithmetic operations with the values ​​of environment variables,
Moreover, you do not need to enter % signs to get values. If the team
SET /A is called from the command line, not from a batch file, it outputs
the final meaning of the expression. To the left of any assignment operator
must be the name of the environment variable. Numeric values are considered as
decimals unless preceded by a 0x prefix for hexadecimal numbers,
and 0 for octal numbers. For example, the numbers 0x12,
and 022 stand for decimal number 18. Pay attention to the recording
octal numbers: 08 and 09 are not valid numbers because in
octal system In calculus the numbers 8 and 9 are not used.

The /P switch allows you to set the value of a variable for the input string entered
user. Shows the specified promptString before reading
entered string. The promptString prompt may be empty.

Environment variable substitution can be expanded as follows:

%PATH:str1=str2%

will extend the effect of the PATH environment variable by replacing every occurrence of "str1" in
expanded result on "str2". "str2" can be an empty string for
effective removal occurrences of "str1" from the expanded output. "str1" can
start with an asterisk, in which case it will match any
start of the extended output until the first occurrence of the remaining part of "str1".

You can also use extension strings.

%PATH:~10.5%

will extend the effect of the PATH environment variable, then use only 5
characters that start with the 11th character (skipping 10) extended
result. If length is not specified, the remaining one is used by default.
variable value. If both values ​​(length and number of characters to skip)
are negative, the next value used will be the length of the variable value
environment added to the specified skip value or specified length.

%PATH:~-10%

will extract the last 10 characters of the PATH variable.

%PATH:~0.-2%

will extract all characters of the PATH variable except the last 2.

Finally added runtime binding support for environment variables
environment.
By default this support is disabled. /V command line switch
CMD.EXE allows you to turn it on and off. To access help, type CMD /?

Runtime binding for environment variables is useful when working around
limitations of early binding, which occurs when the text is first read
line, and not when executing it. The following example demonstrates the emerging
problem when using early variable binding:

set VAR=before
if "%VAR% " == "before" (
set VAR=after
if "%VAR%" == "after" @echo Body of the internal comparison operator
)

This message will not be displayed, because %VAR% in BOTH IF expressions
is substituted at the time of first use in the first IF, including in the body
the first IF branch, which is a compound expression. In IF inside
compound expression actually compares the values ​​of "before" and
"after", which is obviously false. The following example demonstrates a similar error:

set LIST=
for %i in (*) do set LIST=%LIST% %i
echo%LIST%

V in this case the list of files in the current folder will never be built. Instead of
Therefore, the value of the LIST variable will be the name of the last found file.
Again, this happened because %LIST% is substituted only once -
at the time of processing FOR expressions when the list is still empty.
In fact, the above snippet is equivalent to next example:

for %i in (*) do set LIST=%i

in which the name of the last found file is stored in the LIST variable.

Runtime binding for environment variables occurs when
using a special character ( exclamation point), denoting
performing the comparison at runtime. If linking support is enabled
runtime, then to achieve the expected results given above
the snippets should be modified as follows:

set VAR=before
if "%VAR% " == "before" (
set VAR=after
if "!VAR! " == "after" @echo Body of the internal comparison operator
)

set LIST=
for %i in (*) do set LIST=!LIST! %i
echo%LIST%

Several variables are available when enhanced command processing is enabled
environments that do not appear in the list displayed when calling the SET command.
The values ​​of these variables are calculated dynamically each time they are retrieved.
If the user explicitly defines variables with one of these names,
then this definition overlaps the corresponding dynamic definition,
described below:

%CD% - expands to the current directory line.

%DATE% - expands at current date, using the same DATE command format.

%TIME% - expands to the current date using the TIME command format.

%RANDOM% - expands to a random decimal number between 0 and 32767.

%ERRORLEVEL% - expands to the current ERRORLEVEL value

%CMDEXTVERSION% - expands to the current value of the extended command processing version.

%CMDCMDLINE% - expands to original command line which caused
command processor.

Environment variables set in my Windows XP, which has been living for 2 years without reinstallation:

%ALLUSERSPROFILE% = C:\Documents and Settings\All Users
%CommonProgramFiles% = C:\Program Files\Common Files
%COMPUTERNAME% = "Computer name"
%ComSpec% = C:\WINDOWS\system32\cmd.exe
%CYGWIN% = tty
%FP_NO_HOST_CHECK% = NO
%NUMBER_OF_PROCESSORS% = 2
%OS% = Windows_NT
%Path% = C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOW S\System32\Wbem
%PATHEXT% = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.W SF;.WSH
%PROCESSOR_ARCHITECTURE% = x86
%PROCESSOR_IDENTIFIER% = x86 Family 6 Model 15 Stepping 2, GenuineIntel
%PROCESSOR_LEVEL% = 6
%PROCESSOR_REVISION% = 0f02
%ProgramFiles% = C:\Program Files
%PROMPT% = $P$G
%SystemDrive% = C:
%SystemRoot% = C:\WINDOWS
%TEMP% = C:\DOCUME~1\"Username"\LOCALS~1\Temp
%TMP% = C:\DOCUME~1\"Username"\LOCALS~1\Temp
%USERDOMAIN% = "Computer name"
%USERNAME% = "Username"
%USERPROFILE% = C:\Documents and Settings\"Username"
%windir% = C:\WINDOWS

In Windows XP, the command interpreter cmd.exe when easy start, without specifying command line parameters, displays the version of the operating system, information about the copyright protection of OS developers and, in fact, the command line itself, in which you can enter both the command line parameter of the cmd.exe program itself and any external command, for example, the command to launch another application or standard command, such as mkdir, del, etc. If you specify command line parameters, you naturally get some additional features. The syntax in this case is:

CMD [command]

Here the command, in fact, specifies executable command or program. You can use several commands at the same time, using a special separator between them - the characters &&, and the entire combination of several commands must be enclosed in quotation marks, for example, “command&&command&&command”.

Now, almost in accordance with the official Microsoft documentation (I took the liberty of editing it, making it a little more understandable for the people, if this is even possible in this case), I will try to decipher the meaning of each parameter:

/?

Calling up the help (very detailed, on the basis of which this article was actually written).

/A

Output of execution results given command in ANSI format.

/C

Executes the given command and then exits (that is, the console window closes).

/D

Disabling the execution of AutoRun commands (which are the first to be automatically executed when cmd.exe is called) specified in special registry sections (parameters such as REG_SZ are set in this section) and (parameters such as REG_EXPAND_SZ are set in this section).

/E:ON (/E:OFF)

Allowing (denying) command extensions. In Windows XP, enhanced processing of all cmd.exe commands is enabled by default; this setting is used to enable/disable extensions for a specific process.

Completely disable or enable advanced processing on this computer or for specific user possible in the registry, in the sections corresponding to the required context and .

The parameter "EnableExtensions"=dword:00000001 in these sections enables extensions, and "EnableExtensions"=dword:00000000 disables them, with user settings taking precedence over computer settings, and the value of the shell parameter /E taking precedence over registry settings.

With advanced command processing, changes and/or additions affect following commands: assoc, call, chdir (cd), color, del (erase), endlocal, for, ftype, goto, if, mkdir (md), popd, prompt, pushd, set, setlocal, shift, start (call of external commands); /F:ON (/F:OFF) - allows (prohibits) the completion of file and folder names (disabled by default) for a specific cmd.exe call. Enough convenient function, which allows you not to enter completely manually in the console window the paths to files or the names of the folders themselves, but to enter only a part long way and by pressing special combination give keys operating system find suitable options and simply select the one you need.

If you want to enable or disable name completion for all calls to cmd.exe, then in the registry keys (for local machine), (For current user) install following parameters(default values ​​shown):

"CompletionChar"=dword:00000040
"PathCompletionChar"=dword:00000040

so that their hexadecimal values ​​correspond to the control character code used for a particular function (for example, 0 x 4 for Ctrl+D or 0 x 6 for Ctrl+F). This can be done by the well-known utility, repeatedly mentioned and described in our magazine, TweakUI.

User settings take precedence over computer settings, and the value of the /F shell parameter takes precedence over registry settings.

Microsoft provides some clarification regarding the use of this feature: "If completion is enabled using the /F:ON command line switch, two control characters are used: Ctrl+D for folder names and Ctrl+F for file names. To disable a specific completion character in system registry, the special character code is the hexadecimal value of the space character (0 x 20).Completion is called when one of these two special characters is entered.

The completion function takes the path string to the left of the input point, appends a wildcard character to it if it doesn't have one, and then builds a list of paths that match the resulting definition. The first element of this list of matching paths is then printed. If the list is empty, a beep sounds and nothing is displayed. Entering the same special character again then cycles through all matching paths.

Pressing Shift keys when entering a control character, allows you to view the list of paths in reverse order. If you change the output path and then enter the control character again, the saved list is cleared and a new list of paths is built. The same thing happens if you switch from one completion symbol to another. The only difference when using the file terminator is that both the path and the file name are taken to build the match list, while when using the folder terminator, only the path is used.

When a folder terminator is used in one of the built-in folder manipulation commands (CD, MD, or RD), the folder terminator is always implied.

The terminator also works correctly with file names that contain spaces or other special characters, as long as the matching string is enclosed in quotation marks. Additionally, if you move the insertion point to the left and then use a trailing character within a line, the remaining text to the right of the insertion point will be discarded.

Special characters that require quotation marks:

<пробел> & () { } ^ = ; ! ’ + , ` ~ "

All clear?

/K

Execute a given command without subsequently terminating (here the console window will not close).

/Q

Disable the output of commands to the screen (ECHO OFF).

/R

Same as /C.

/S

Change command behavior after /C or /K.

/T:color

Set the text and background color of the console window.

The color parameter has a value in the form of two hexadecimal numbers: the first specifies the background color of the window, and the second specifies the text in the window. If the set of colors did not change at the time cmd.exe was launched (for example, by another shell session), then by default the registry setting that defines appearance consoles:

"DefaultColor"=dword:00000000

The correspondence of these numbers to colors is given in the table.

That is, the result of executing this command “CMD /T:7C” will be light red letters on a white background.

/U

Output the command execution results in Unicode format.

/V:ON (/V:OFF)

Allow (disable) delayed expansion of environment variables (for a specific cmd.exe call) using the exclamation mark "!" as a separator. For example, /V:ON allows the use of!var! as a runtime expansion of var. The var syntax is used to expand variables on input, which produces very different results inside a FOR loop.

Also, delayed expansion of environment variables can be enabled or disabled in the registry, in the sections (for the local machine), (for the current user) by setting the parameter "DelayedExpansion"=dword:00000001 to enable and "DelayedExpansion"=dword:00000000 to disable.

User settings take precedence over computer settings, and the value of the /V shell parameter takes precedence over registry settings.

When lazy expansion of environment variables is enabled, the "!" (the symbol is an exclamation point) can be used to replace the current value of an environment variable at run time.

/X

Means the same as /E:ON, for compatibility reasons.

/Y

Same as /E:OFF.

And finally, a few more valuable comments.

If the /C or /K switch is specified, the rest of the command line after that switch is treated as the command line, and quotation marks (") are treated as such. Quote characters on the command line are preserved if all of the following conditions are true:

  • the /S key is missing;
  • there are exactly two quotation marks;
  • There are no other special characters between them, such as: &< > () @ ^ |;
  • there are one or more spaces between them;
  • the string enclosed in quotes is the name of the executable file.

Otherwise, the first character is checked and if it is a quote character, it is removed, the last quote character on the command line is also removed, and all text after that last quote character is retained.

Displaying, setting and deleting cmd.exe environment variables.

SET [variable=[string]]

variable The name of the environment variable.

string A character string assigned to the specified variable.

Type SET without parameters to display the current environment variables.

Changing the SET command when enabling enhanced command processing:

If, when calling, you specify only the variable name without an equal sign and a value,

The SET command will print the values ​​of all variables whose names begin with

from the specified line. For example:

This command will print the values ​​of all variables whose names begin with "P".

If the variable name is not found in the current environment, the SET command returns

will set the error value to ERRORLEVEL 1.

The SET command does not allow an equal sign in the name

environment variable.

The SET command supports two additional switches:

SET /A expression

SET /P variable=

The /A switch indicates that the string to the right of the equals sign is numeric

expression whose value is calculated. The expression handler is very

is simple and supports the following operations, listed in descending order

priority:

() - grouping

! ~ - - unary operators

*/% - arithmetic operators

Arithmetic operators

<< >> - binary shift

& - binary AND

^ - binary exclusive OR

| - binary OR

= *= /= %= += -= - assignment

&= ^= |= <<= >>=

Statement separator

When using any logical or binary operators, you must

enclose the expression string in quotes. Any non-numeric strings in the expression

are treated as names of environment variables whose values ​​are converted

into numerical form before use. If a variable with the specified name

is not defined in the system, a null value is substituted. This

allows you to perform arithmetic operations with the values ​​of environment variables,

Moreover, you do not need to enter % signs to get values. If the team

SET /A is called from the command line, not from a batch file, it outputs

the final meaning of the expression. To the left of any assignment operator

must be the name of the environment variable. Numeric values ​​are treated as

decimal, unless preceded by a 0x prefix for hexadecimal numbers,

and 0 for octal numbers. For example, the numbers 0x12,

and 022 represent the decimal number 18. Note the notation

octal numbers: 08 and 09 are not valid numbers because in

The octal number system does not use the numbers 8 and 9.

The /P switch allows you to set the value of a variable for the input string entered

user. Shows the specified promptString before reading

entered string. The promptString prompt may be empty.

Environment variable substitution can be expanded as follows:

%PATH:str1=str2%

will extend the effect of the PATH environment variable by replacing every occurrence of "str1" in

expanded result on "str2". "str2" can be an empty string for

effectively removing occurrences of "str1" from the expanded output. "str1" can

start with an asterisk, in which case it will match any

start of the extended output until the first occurrence of the remaining part of "str1".

You can also use extension strings.

will extend the effect of the PATH environment variable, then use only 5

characters that start with the 11th character (skipping 10) extended

result. If length is not specified, the remaining one is used by default.

variable value. If both values ​​(length and number of characters to skip)

are negative, the next value used will be the length of the variable value

environment added to the specified skip value or specified length.

will extract the last 10 characters of the PATH variable.

will extract all characters of the PATH variable except the last 2.

Finally added runtime binding support for environment variables

environment. By default this support is disabled. /V command line switch

CMD.EXE allows you to turn it on and off. To access help, type CMD /?

Runtime binding for environment variables is useful when working around

limitations of early binding, which occurs when the text is first read

line, and not when executing it. The following example demonstrates the emerging

problem when using early variable binding:

set VAR=before

If "%VAR%" == "before" (

if "%VAR%" == "after" @echo Body of the internal comparison operator

This message will not be displayed, because %VAR% in BOTH IF expressions

is substituted at the time of first use in the first IF, including in the body

the first IF branch, which is a compound expression. In IF inside

compound expression actually compares the values ​​of "before" and

"after", which is obviously false. The following example demonstrates a similar error:

set LIST=

For %i in (*) do set LIST=%LIST% %i

in this case, the list of files in the current folder will never be built. Instead of

Therefore, the value of the LIST variable will be the name of the last found file.

Again, this happened because %LIST% is substituted only once -

at the moment of processing the FOR expression, when the list is still empty.

In fact, the above snippet is equivalent to the following example:

for %i in (*) do set LIST= %i

in which the name of the last found file is stored in the LIST variable.

Runtime binding for environment variables occurs when

using a special character (exclamation mark) to indicate

performing the comparison at runtime. If linking support is enabled

runtime, then to achieve the expected results given above

the snippets should be modified as follows:

set VAR=before

If "%VAR%" == "before" (

Set VAR=after

If "!VAR!" == "after" @echo Body of internal comparison operator

Set LIST=

For %i in (*) do set LIST=!LIST!%i

Several variables are available when enhanced command processing is enabled

environments that do not appear in the list displayed when calling the SET command.

The values ​​of these variables are calculated dynamically each time they are retrieved.

If the user explicitly defines variables with one of these names,

then this definition overlaps the corresponding dynamic definition,

described below:

%CD% - expands to the current directory line.

%DATE% - Expands to the current date using the same DATE command format.

%TIME% - expands to the current date using the TIME command format.

%RANDOM% - expands to a random decimal number between 0 and 32767.

%ERRORLEVEL% - expands to the current ERRORLEVEL value

%CMDEXTVERSION% - expands to the current version value

advanced command processing.

%CMDCMDLINE% - Expands to the original command line that called

command processor.







2024 gtavrl.ru.