ENVIRON(7) | Linux Programmer's Manual | ENVIRON(7) |
environ - ユーザー環境
extern char **environ;
The variable environ points to an array of pointers to strings called the "environment". The last pointer in this array has the value NULL. (This variable must be declared in the user program, but is declared in the header file <unistd.h> if the _GNU_SOURCE feature test macro is defined.) This array of strings is made available to the process by the exec(3) call that started the process. When a child process is created via fork(2), it inherits a copy of its parent's environment.
通例では、 environ の文字列は "name=value" という書式をとる。 よく用いられる例を以下に示す。
Names may be placed in the shell's environment by the export command in sh(1), or by the setenv command if you use csh(1).
The initial environment of the shell is populated in various ways, such as definitions from /etc/environment that are processed by pam_env(8) for all users at login time (on systems that employ pam(8)). In addition, various shell initialization scripts, such as the system-wide /etc/profile script and per-user initializations script may include commands that add variables to the shell's environment; see the manual page of your preferred shell for details.
Bourne-style shells support the syntax
NAME=value command
to create an environment variable definition only in the scope of the process that executes command. Multiple variable definitions, separated by white space, may precede command.
exec(3) の引数としても環境を設定することができる。 C プログラムからは、 getenv(3), putenv(3), setenv(3), unsetenv(3) などの関数を用いて環境を扱うことができる。
Note that the behavior of many programs and library routines is influenced by the presence or value of certain environment variables. Examples include the following:
The prctl(2) PR_SET_MM_ENV_START and PR_SET_MM_ENV_END operations can be used to control the location of the process's environment.
これらの中には、明らかにセキュリティ上の危険が存在する。 ユーザーが IFS や LD_LIBRARY_PATH に異常な値を与えたことによって、 これまで多くのシステムコマンドがだまされて、 システムをひどい目にあわせてきた。
名前空間が汚染される危険性も存在する。 make や autoconf のようなプログラムでは、デフォルトのユーティリティを 環境にある似たような名前の変数で上書きすることができる (通常はすべて大文字の変数を用いる)。 すなわち、利用したい C コンパイラは CC で選択できる。また同様に MAKE, AR, AS, FC, LD, LEX, RM, YACC なども用いることができる。 ところが一方では、このような変数を (パス名ではなく) プログラムに対するオプションとして扱うような流儀も存在してきた。 例えば MORE, LESS, GZIP などがそうである。 このような利用法は間違っていると考えるべきで、 新しいプログラムでは避けるべきである。 gzip の作者たちは、オプションを与える環境変数を GZIP_OPT に改名することを考えるほうがよい。
bash(1), csh(1), env(1), login(1), printenv(1), sh(1), tcsh(1), execve(2), clearenv(3), exec(3), getenv(3), putenv(3), setenv(3), unsetenv(3), locale(7), ld.so(8), pam_env(8)
この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。
2020-08-13 | Linux |