env 명령어 (AIX 5.3·6.1)
https://archive.horanglab.com/posts/aix-cmd-env
핵심 정리
- 인수 없이 실행하면 현재 환경 변수를 한 줄에 하나씩
이름=값으로 보여 줍니다. env 이름=값 ... 명령은 바꾼 환경에서 명령을 실행하며, 바뀐 값은 그 명령이 도는 동안만 적용됩니다.-i(또는-)는 물려받은 환경을 버리고 지정한 변수만으로 명령을 실행합니다.env 이름으로 변수 하나만 볼 수 있습니다.- 종료 상태는 실행한 명령의 것이며, 명령을 찾았지만 실행할 수 없으면 126, 찾을 수 없으면 127입니다.
- AIX 5.3과 6.1 문서의 내용이 같습니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (두 버전 내용 같음) |
| 원문 | IBM Commands Reference — 5.3 Volume 2, 6.1 Volume 2 |
| 파일 | /usr/bin/env |
| 관련 명령어 | printenv, set, export |
목적
현재 환경을 보여 주거나, 바꾼 환경에서 명령을 실행합니다.
영어 원문
Displays the current environment or sets the environment for the execution of a command.
구문
환경 변수 여러 개를 보이거나 바꾼 환경에서 실행할 때:
env [ -i | - ] [ Name=Value ] ... [ Command [ Argument ... ] ]
환경 변수 하나를 볼 때:
env [ Name ]
설명
env 명령은 현재 환경을 보여 주거나, 지정한 명령을 바꾼 환경에서 실행하게 합니다.
플래그나 매개변수가 없으면 현재 환경을 한 줄에 Name=Value 쌍 하나씩 보여 줍니다.
영어 원문
The env command allows you to display your current environment or run a specified command in a changed environment.
If no flags or parameters are specified, the env command displays your current environment, showing one Name=Value pair per line.
플래그
| 플래그 | 설명 |
|---|---|
-i |
물려받은 환경을 무시하고, Name=Value 매개변수로 지정한 환경으로 Command를 실행합니다. 구문의 -도 같은 뜻입니다. |
영어 원문
-i— Ignores the inherited environment and invokes the command specified by the Command parameter with the environment specified by the Name=Value parameters.
매개변수
| 매개변수 | 설명 |
|---|---|
Name=Value |
Name=Value를 하나 이상 지정하면 현재 환경을 바꾼 판에서 명령을 실행합니다. 현재 환경 전체를 지정한 값으로 바꾸려면 -i를 씁니다. 어느 경우든 환경 변경은 지정한 명령이 도는 동안만 적용됩니다. |
| Command | 실행할 명령이며, Argument를 붙일 수 있습니다. Korn 셸의 특수 내장 명령을 지정하면 결과가 정해져 있지 않습니다. Korn 셸 내장 명령은 ksh 명령에서 설명합니다. |
영어 원문
- Name=Value — You can run a command in a modified version of the current environment by specifying one or more Name=Value parameters. Use the
-iflag if you wish to replace the entire current environment with the specified Name =Value parameters. In either case, environment changes are effective only while the specified command is running. - Command — The Command parameter has an optional Argument variable. If the specified command is one of the Korn shell special built-in commands, results are unspecified. Korn shell built-in commands are described in the ksh command.
종료 상태
Command를 지정하면 그 명령의 종료 상태가 env의 종료 상태입니다. 그렇지 않으면 다음 값 중 하나로 끝납니다.
| 값 | 뜻 |
|---|---|
| 0 | 잘 끝났습니다. |
| 1~125 | env에서 오류가 났습니다. |
| 126 | Command로 지정한 명령을 찾았지만 실행할 수 없었습니다. |
| 127 | Command로 지정한 명령을 찾지 못했습니다. |
영어 원문
If the Command parameter is specified, the exit status of the env command is the exit status of the command specified in the Command parameter. Otherwise, the env command exits with one of the following values:
- 0 — The env command completed successfully.
- 1-125 — An error occurred in the env command.
- 126 — The command specified by the Command parameter was found, but could not be invoked.
- 127 — The command specified by the Command parameter was not found.
예제
date를 실행하는 동안만TZ환경 변수를 바꿉니다. 다음 두 명령은 같으며, 산악 시간대의 현재 날짜와 시각을 보여 줍니다.date가 끝나면TZ는 이전 값으로 돌아갑니다.
TZ=MST7MDT date
env TZ=MST7MDT date
PATH,IDIR,LIBDIR만 있는 환경에서make를 실행합니다. 셸이make를 찾을 수 있게PATH를 꼭 지정해야 합니다.make가 끝나면 이전 환경으로 돌아갑니다.
env -i PATH=$PATH IDIR=/$HOME/include LIBDIR=/$HOME/lib make
영어 원문
- To change the TZ environment variable while running the date command, type:
TZ=MST7MDT date
OR
env TZ=MST7MDT date
Each of these commands displays the time in mountain time and the current date. The two commands shown are equivalent. When the date command is finished, the previous value of the TZ environment variable takes effect again.
- To run the make command in an environment that consists only of definitions for the PATH, IDIR, and LIBDIR environment variables, type:
env -i PATH=$PATH IDIR=/$HOME/include LIBDIR=/$HOME/lib make
You must specify the PATH environment variable so that the shell can find the make command. When the make command is finished, the previous environment takes effect.
파일
| 파일 | 설명 |
|---|---|
/usr/bin/env |
env 명령이 들어 있습니다. |
관련 명령어: printenv. /etc/environment 파일과 .profile 형식도 참고합니다.
영어 원문
- /usr/bin/env — Contains the env command.
Related information:
- printenv command
- environment command
- profile file format
- Profiles overview
리눅스(GNU)와 다른 점
GNU env도 같은 구문(-i, -, 이름=값)을 씁니다. GNU에는 -u 이름(변수 빼기), -0, -C 디렉터리, -S(셔뱅 줄의 인수 나누기)가 더 있지만 AIX 문서에는 없습니다. 스크립트 첫 줄의 #!/usr/bin/env ksh 같은 쓰임은 AIX에서도 같습니다.