Environment Variables#

Environment Variables#

  • Environment variables are a process attribute (not related to any programming language)

  • Inherited to child processes

  • A process can use getenv() (here) to read its value

../../../../../../../_images/environ-inherit.svg
#include <stdlib.h>
#include <print>

int main(int argc, char** argv)
{
    const char* foo_value = getenv("FOO");
    if (foo_value != nullptr)
        std::println("FOO={}", foo_value);
    else
        std::println("FOO is not set");

    return 0;
}
$ ./sysprog-process-environ
FOO is not set
$ export FOO=bar
$ ./sysprog-process-environ
FOO=bar