다음을 통해 공유


set(환경 변수)

cmd.exe 환경 변수를 표시, 설정 또는 제거합니다. If used without parameters, set displays the current environment variable settings.

Note

이 명령은 기본적으로 사용 하도록 설정 된 명령 확장 필요 합니다.

The set command can also run from the Windows Recovery Console, using different parameters. 보다 자세한 내용은 Windows 복구 환경(WinRE)을 참조하세요.

Syntax

set [<variable>=[<string>]]
set [/p] <variable>=[<promptString>]
set /a <variable>=<expression>

Parameters

Parameter Description
<variable> 설정 하거나 수정 하는 환경 변수를 지정 합니다.
<string> 지정된 된 환경 변수와 연결할 문자열을 지정 합니다.
/p <variable> 의 값을 사용자가 입력한 입력 줄로 설정합니다.
<promptstring> 입력에 대 한 사용자에 게 묻는 메시지를 지정 합니다. This parameter must be used with the /p parameter.
/a <string>을 평가되는 숫자 식으로 설정합니다.
<expression> 숫자 식을 지정합니다.
/? 명령 프롬프트에 도움말을 표시합니다.

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.

  • <, >, |, &, ^ 문자는 특수 명령 셸 문자이며, ^에서 사용될 경우 이스케이프 문자(<string>) 또는 따옴표로 묶어야 합니다(예: "StringContaining&Symbol"). 따옴표를 사용하여 특수 문자 중 하나를 포함하는 문자열을 묶을 경우 따옴표는 환경 변수 값의 일부로 설정됩니다.

  • 환경 변수를 사용 하 여 일부 배치 파일이 나 프로그램의 동작을 제어 하 고 방법은 창 및 MS-DOS 제어를 하위 시스템 표시 및 작동 합니다. 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.

  • <variable><string>의 값을 지정하는 경우 지정된 <variable> 값이 환경에 추가되고 <string>이 해당 변수에 연결됩니다. 변수는 환경에 이미 있는 경우 새 문자열 값을는 이전 문자열 값을으로 바꿉니다.

  • If you specify only a variable and an equal sign (without <string>) for the set command, the <string> value associated with the variable is cleared (as if the variable isn't 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
    ^ 비트 배타적 OR
    = *= /= %= += -= &= ^= = <<= >>=
    , Expression separator
  • 논리(&& 또는 ||) 또는 모듈러스(%) 연산자를 사용하는 경우 식 문자열을 따옴표로 묶습니다. 식에서 숫자가 아닌 모든 문자열은 환경 변수 이름으로 간주되며 해당 값은 처리되기 전에 숫자로 변환됩니다. 현재 환경에 정의되지 않은 환경 변수 이름을 지정하면 0 값이 할당되므로 %를 사용하여 값을 검색하지 않고도 환경 변수 값으로 산술 연산을 수행할 수 있습니다.

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

  • 숫자 값에는 10 진수 0 ×는 16 진수 또는 8 진수 숫자의 경우 0을 접두사로 붙지 않는 경우입니다. 따라서 0 × 12는 18, 같은 또는 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.

  • 배치 파일에서 변수 값을 호출하는 경우 값을 퍼센트 기호(%)로 묶습니다. 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:

set testVar=TEST^^1

The set command assigns everything that follows the equal sign (=) to the value of the variable. 따라서 set testVar=TEST^1을 입력하면 다음과 같은 결과가 표시됩니다. testVar=TEST1

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

set testVar=TEST^&1

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

set include=c:\directory

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:

@echo off
rem ADDPATH.BAT adds a new directory
rem to the path environment variable.
set path=%1;%path%
set

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

set p

현재 디바이스의 모든 환경 변수 목록을 표시하려면 다음을 입력합니다.

set