Part 1
요약·해설
BOARD, BUILD_VERSION, ALERT 예제로 environment variable의 전체 수명주기를 확인합니다.
setenv()
env get
unsetenv()
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
DE1AC42C14A5FB953B8F3FD7E2243CFD4D4B58FF554F4383D3C481656E8D41A1
.. _posix-env-sample:
POSIX Environment Variables
###########################
Overview
********
In this sample application, the POSIX :c:func:`setenv`, function is used to populate several environment
variables in C. Then, all environment variables are then printed.
If the user sets a new value for the ``ALERT`` environment variable, it is printed to standard
output, and then cleared via :c:func:`unsetenv`.
Building and Running
********************
This project outputs to the console. It can be built and executed on QEMU as follows:
.. zephyr-app-commands::
:zephyr-app: samples/posix/env
:host-os: unix
:board: qemu_riscv32
:goals: run
:compact:
Sample Output
=============
The program below shows sample output for a specific Zephyr build.
.. code-block:: console
BOARD=qemu_riscv32
BUILD_VERSION=zephyr-v3.5.0-5372-g3a46f2d052c7
ALERT=
Setting Environment Variables
=============================
The shell command below shows how to create a new environment variable or update the value
associated with an existing environment variable.
The C code that is part of this sample application displays the value associated with the
``ALERT`` environment variable and then immediately unsets it.
.. code-block:: console
uart:~$ posix env set ALERT="Happy Friday!"
uart:~$ ALERT="Happy Friday!"
uart:~$ posix env set HOME="127.0.0.1"
uart:~$
Getting Environment Variables
=============================
The shell command below may be used to display the value associated with one environment variable.
.. code-block:: console
uart:~$ posix env get BOARD
qemu_riscv32
The shell command below may be used to display all environment variables and their associated
values.
.. code-block:: console
uart:~$ posix env get
BOARD=qemu_riscv32
BUILD_VERSION=zephyr-v3.5.0-5372-g3a46f2d052c7
ALERT=
Unsetting Environment Variables
===============================
The shell command below may be used to unset environment variables.
.. code-block:: console
uart:~$ posix env unset BOARD
Part 3
한국어 전문 번역
개요
이 sample application은 POSIX setenv() 함수를 사용해 C code에서 여러 environment variable을 채운 뒤, 모든 environment variable을 출력합니다.
사용자가 ALERT environment variable에 새 값을 설정하면 그 값을 standard output에 출력하고, 이어서 unsetenv()로 지웁니다.
빌드 및 실행
이 project는 console에 결과를 출력합니다. QEMU에서 다음과 같이 build하고 실행할 수 있습니다.
west build -b qemu_riscv32 samples/posix/env
west build -t run
출력 예
아래는 특정 Zephyr build에서 program이 출력한 예입니다.
BOARD=qemu_riscv32
BUILD_VERSION=zephyr-v3.5.0-5372-g3a46f2d052c7
ALERT=
Environment variable 설정
아래 shell command는 새 environment variable을 만들거나 기존 environment variable에 연결된 값을 갱신하는 방법을 보여 줍니다.
이 sample application의 C code는 ALERT environment variable에 연결된 값을 표시한 다음 즉시 그 변수를 해제합니다.
uart:~$ posix env set ALERT="Happy Friday!"
uart:~$ ALERT="Happy Friday!"
uart:~$ posix env set HOME="127.0.0.1"
uart:~$
Environment variable 읽기
아래 shell command로 environment variable 하나에 연결된 값을 표시할 수 있습니다.
uart:~$ posix env get BOARD
qemu_riscv32
인자 없이 명령을 실행하면 모든 environment variable과 각각에 연결된 값을 표시합니다.
uart:~$ posix env get
BOARD=qemu_riscv32
BUILD_VERSION=zephyr-v3.5.0-5372-g3a46f2d052c7
ALERT=
Environment variable 해제
아래 shell command로 environment variable을 해제할 수 있습니다.
uart:~$ posix env unset BOARD
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.