Windows set command result

Set (переменная среды) set (environment variable)

Отображает, устанавливает или удаляет переменные среды cmd.exe. Displays, sets, or removes cmd.exe environment variables. Если используется без параметров, Set отображает текущие параметры переменной среды. If used without parameters, set displays the current environment variable settings.

Для этой команды требуются расширения команд, которые включены по умолчанию. This command requires command extensions, which are enabled by default.

Команда Set также может запускаться из консоли восстановления Windows с использованием различных параметров. The set command can also run from the Windows Recovery Console, using different parameters. Дополнительные сведения см. в разделе Среда восстановления Windows (WinRE). For more information, see Windows Recovery Environment (WinRE).

Синтаксис Syntax

Параметры Parameters

Параметр Parameter Описание: Description
Задает переменную среды, которую необходимо задать или изменить. Specifies the environment variable to set or modify.
Указывает строку, связываемую с указанной переменной среды. Specifies the string to associate with the specified environment variable.
/p /p Присваивает значение строке ввода, введенному пользователем. Sets the value of to a line of input entered by the user.
Указывает сообщение, предлагающее пользователю ввести данные. Specifies a message to prompt the user for input. Этот параметр должен использоваться с параметром /p . This parameter must be used with the /p parameter.
/a /a Задает числовое выражение, которое вычисляется. Sets to a numerical expression that is evaluated.
Задает числовое выражение. Specifies a numerical expression.
/? /? Отображение справки в командной строке. Displays help at the command prompt.

Комментарии Remarks

Если расширения команд включены (по умолчанию) и вы запускаете Set со значением, отображаются все переменные, которые начинаются с этого значения. If command extensions are enabled (the default) and you run set with a value, it displays all of the variables that begin with that value.

Символы ,, > , | & и ^ являются специальными символами командной оболочки и перед ними должны начинаться escape-символом ( ^ ) или заключены в кавычки (например , «стрингконтаининг&Symbol»). The characters , > , | , & , and ^ are special command shell characters, and they must be preceded by the escape character ( ^ ) or enclosed in quotation marks when used in (for example, «StringContaining&Symbol»). Если строка, содержащая специальный символ, заключена в кавычки, кавычки необходимо указывать как часть значения переменной среды. If you use quotation marks to enclose a string that contains one of the special characters, the quotation marks are set as part of the environment variable value.

Используйте переменные среды для управления поведением некоторых пакетных файлов и программ, а также для управления отображением окон и подсистемы MS-DOS. Use environment variables to control the behavior of some batch files and programs and to control the way Windows and the MS-DOS subsystem appears and works. Команда Set часто используется в файле Autoexec. NT для задания переменных среды. The set command is often used in the Autoexec.nt file to set environment variables.

Если вы используете команду Set без параметров, отображаются текущие параметры среды. If you use the set command without any parameters, the current environment settings are displayed. Эти параметры обычно включают переменные среды ComSpec и path , которые используются для поиска программ на диске. These settings usually include the COMSPEC and PATH environment variables, which are used to help find programs on disk. В Windows используются две другие переменные среды: Prompt и DIRCMD. Two other environment variables used by Windows are PROMPT and DIRCMD.

Если заданы значения для и , указанное значение добавляется в среду и связывается с этой переменной. If you specify values for and , the specified value is added to the environment and is associated with that variable. Если переменная уже существует в среде, новое строковое значение заменяет старое. If the variable already exists in the environment, the new string value replaces the old string value.

Если указать только переменную и знак равенства (без ) для команды Set , значение, связанное с переменной, будет очищаться (как если бы переменная отсутствует). If you specify only a variable and an equal sign (without ) for the set command, the value associated with the variable is cleared (as if the variable is not there).

При использовании параметра /a поддерживаются следующие операторы в порядке убывания приоритета. If you use the /a parameter, the following operators are supported, in descending order of precedence:

Оператор Operator Выполненная операция Operation performed
( ) Группирование Grouping
!

Унарный Unary
* / % Арифметические Arithmetic
+ — Арифметические Arithmetic
> Логическая смена Logical shift
& Побитовое И Bitwise AND
^ Побитовое исключающее ИЛИ Bitwise exclusive OR
= *= /= %= += -= &= ^= = >=
, Разделитель выражений Expression separator

Если используются операторы логического ( && или || ) или модуля ( % ), заключите строку выражения в кавычки. If you use logical ( && or || ) or modulus (%) operators, enclose the expression string in quotation marks. Все нечисловые строки в выражении считаются именами переменных среды, и их значения преобразуются в числа до их обработки. Any non-numeric strings in the expression are considered environment variable names, and their values are converted to numbers before they are processed. Если указать имя переменной среды, которое не определено в текущей среде, то выделяется нулевое значение, что позволяет выполнять арифметические операции со значениями переменных среды без использования% для получения значения. If you specify an environment variable name that is not defined in the current environment, a value of zero is allotted, which allows you to perform arithmetic with environment variable values without using the % to retrieve a value.

При запуске set/a из командной строки за пределами командного скрипта отображается конечное значение выражения. If you run set /a from the command line outside of a command script, it displays the final value of the expression.

Числовые значения — это десятичные числа, кроме префикса 0 × для шестнадцатеричных чисел или 0. Numeric values are decimal numbers unless prefixed by 0× for hexadecimal numbers or 0 for octal numbers. Таким образом, 0 × 12 совпадает с 18, что совпадает с 022. Therefore, 0×12 is the same as 18, which is the same as 022.

Отложенная поддержка расширения переменных среды по умолчанию отключена, но ее можно включить или отключить с помощью команды cmd/v. Delayed environment variable expansion support is disabled by default, but you can enable or disable it by using cmd /v.

При создании пакетных файлов можно использовать команду Set для создания переменных, а затем использовать их так же, как и пронумерованные переменные %0%9. When creating batch files, you can use set to create variables, and then use them in the same way that you would use the numbered variables %0 through %9. Можно также использовать переменные %0%9 в качестве входных данных для Set. You can also use the variables %0 through %9 as input for set.

При вызове значения переменной из пакетного файла заключите значение в знаки процента ( % ). If you call a variable value from a batch file, enclose the value with percent signs (%). Например, если программа пакетной службы создает переменную среды с именем бод, можно использовать строку, связанную с параметром бод , в качестве заменяемого параметра, введя % бод% в командной строке. For example, if your batch program creates an environment variable named BAUD, you can use the string associated with BAUD as a replaceable parameter by typing %baud% at the command prompt.

Примеры Examples

Чтобы задать значение Test ^ 1 для переменной среды с именем testVar , введите: To set the value TEST^1 for the environment variable named testVar , type:

Команда Set назначает значение переменной всем, что следует за знаком равенства (=). The set command assigns everything that follows the equal sign (=) to the value of the variable. Поэтому при вводе set testVar=test^1 вы получите следующий результат: testVar=test^1 . Therefore, if you type set testVar=test^1 , you’ll get the following result, testVar=test^1 .

Чтобы задать значение TEST&1 для переменной среды testVar , введите: To set the value TEST&1 for the environment variable testVar , type:

Чтобы задать переменную среды с именем include , с которой связана строка к:\директори , введите: To set an environment variable named INCLUDE so the string c:\directory is associated with it, type:

Затем можно использовать строку к:\директори в пакетных файлах, заключив имя в символы процента ( % ). You can then use the string c:\directory in batch files by enclosing the name INCLUDE with percent signs (%). Например, можно использовать dir %include% в пакетном файле для вывода содержимого каталога, связанного с переменной среды include. For example, you can use dir %include% in a batch file to display the contents of the directory associated with the INCLUDE environment variable. После обработки этой команды строка к:\директори заменяет % include%. After this command is processed, the string c:\directory replaces %include%.

Чтобы использовать команду Set в пакетной программе для добавления нового каталога в переменную среды path , введите: To use the set command in a batch program to add a new directory to the PATH environment variable, type:

Чтобы отобразить список всех переменных среды, начинающихся с буквы P, введите: To display a list of all of the environment variables that begin with the letter P, type:

set (environment variable)

Displays, sets, or removes cmd.exe environment variables. If used without parameters, set displays the current environment variable settings.

This command requires command extensions, which are enabled by default.

The set command can also run from the Windows Recovery Console, using different parameters. For more information, see Windows Recovery Environment (WinRE).

Syntax

Parameters

Parameter Description
Specifies the environment variable to set or modify.
Specifies the string to associate with the specified environment variable.
/p Sets the value of to a line of input entered by the user.
Specifies a message to prompt the user for input. This parameter must be used with the /p parameter.
/a Sets to a numerical expression that is evaluated.
Specifies a numerical expression.
/? Displays help at the command prompt.

Remarks

If command extensions are enabled (the default) and you run set with a value, it displays all of the variables that begin with that value.

The characters , > , | , & , and ^ are special command shell characters, and they must be preceded by the escape character ( ^ ) or enclosed in quotation marks when used in (for example, «StringContaining&Symbol»). If you use quotation marks to enclose a string that contains one of the special characters, the quotation marks are set as part of the environment variable value.

Use environment variables to control the behavior of some batch files and programs and to control the way Windows and the MS-DOS subsystem appears and works. The set command is often used in the Autoexec.nt file to set environment variables.

If you use the set command without any parameters, the current environment settings are displayed. These settings usually include the COMSPEC and PATH environment variables, which are used to help find programs on disk. Two other environment variables used by Windows are PROMPT and DIRCMD.

If you specify values for and , the specified value is added to the environment and is associated with that variable. If the variable already exists in the environment, the new string value replaces the old string value.

If you specify only a variable and an equal sign (without ) for the set command, the value associated with the variable is cleared (as if the variable is not there).

If you use the /a parameter, the following operators are supported, in descending order of precedence:

Operator Operation performed
( ) Grouping
!

Unary
* / % Arithmetic
+ — Arithmetic
> Logical shift
& Bitwise AND
^ Bitwise exclusive OR
= *= /= %= += -= &= ^= = >=
, Expression separator

If you use logical ( && or || ) or modulus (%) operators, enclose the expression string in quotation marks. Any non-numeric strings in the expression are considered environment variable names, and their values are converted to numbers before they are processed. If you specify an environment variable name that is not defined in the current environment, a value of zero is allotted, which allows you to perform arithmetic with environment variable values without using the % to retrieve a value.

If you run set /a from the command line outside of a command script, it displays the final value of the expression.

Numeric values are decimal numbers unless prefixed by 0Г— for hexadecimal numbers or 0 for octal numbers. Therefore, 0Г—12 is the same as 18, which is the same as 022.

Delayed environment variable expansion support is disabled by default, but you can enable or disable it by using cmd /v.

When creating batch files, you can use set to create variables, and then use them in the same way that you would use the numbered variables %0 through %9. You can also use the variables %0 through %9 as input for set.

If you call a variable value from a batch file, enclose the value with percent signs (%). For example, if your batch program creates an environment variable named BAUD, you can use the string associated with BAUD as a replaceable parameter by typing %baud% at the command prompt.

Examples

To set the value TEST^1 for the environment variable named testVar , type:

The set command assigns everything that follows the equal sign (=) to the value of the variable. Therefore, if you type set testVar=test^1 , you’ll get the following result, testVar=test^1 .

To set the value TEST&1 for the environment variable testVar , type:

To set an environment variable named INCLUDE so the string c:\directory is associated with it, type:

You can then use the string c:\directory in batch files by enclosing the name INCLUDE with percent signs (%). For example, you can use dir %include% in a batch file to display the contents of the directory associated with the INCLUDE environment variable. After this command is processed, the string c:\directory replaces %include%.

To use the set command in a batch program to add a new directory to the PATH environment variable, type:

To display a list of all of the environment variables that begin with the letter P, type:

Читайте также:  Mac os ssd не инициализируется
Оцените статью