zephyr/samples/posix/env
Yong Cong Sin bbe5e1e6eb build: namespace the generated headers with zephyr/
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-28 22:03:55 +02:00
..
src build: namespace the generated headers with zephyr/ 2024-05-28 22:03:55 +02:00
CMakeLists.txt samples: posix: add environment variable sample app 2024-03-08 04:28:47 -05:00
prj.conf samples: posix: add environment variable sample app 2024-03-08 04:28:47 -05:00
README.rst samples: posix: add environment variable sample app 2024-03-08 04:28:47 -05:00
sample.yaml samples/posix/env: Change integration platform 2024-05-17 15:07:46 +02:00

.. _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