环境变量是否区分系统环境变量和应用程序环境变量?

huangapple go评论50阅读模式
英文:

Do environment variables distinguish system environment variables from application environment variables?

问题

环境变量是否区分系统环境变量和应用程序环境变量?
还是只是系统环境变量?


编辑-01

我的场景是在Linux中。
顺便问一下,这与操作系统有关吗?

英文:

Do environment variables distinguish system environment variables from application environment variables?
Or is it just a system environment variable?


Edit-01

my scenario is in Linux.
btw, does it have anything to do with the operating system?

答案1

得分: 1

There is more than one way for a POSIX host to create a child process.
One of them is execle.

Note the envp argument.

An interactive shell, such as bash, can export a variable, or not. Non-exported variables are uninteresting, they are not environment vars, as they will not appear within envp.

You were wondering if there is a sys vs app distinction for env vars. There is no such distinction. Either a key=value entry appears in envp, or it does not. If it does, then it is an env var. If it does not, it is some local setting of interest only to the environment where it was assigned a value. Fork a /usr/bin/env child if you want to see current env vars.

Another way is execvpe.

And yes, I know, the typical pattern is fork() and then exec. Though BSD and others have experimented with variations on that theme, to avoid expensive fork work which exec immediately discards.

英文:

There is more than one way for a POSIX host to create a child process.
One of them is
execle.

Note the envp argument.

An interactive shell, such as
bash,
can export a variable, or not.
Non-exported variables are uninteresting, they are not environment vars,
as they will not appear within envp.

You were wondering if there is a sys vs app distinction for env vars.
There is no such distinction.
Either a key=value entry appears in envp, or it does not.
If it does, then it is an env var. If it does not, it is some local setting
of interest only to the environment where it was assigned a value.
Fork a /usr/bin/env child if you want to see current env vars.


Another way is execvpe.

And yes, I know, the typical pattern is fork() and then exec.
Though BSD and others have experimented with variations on
that theme, to avoid expensive fork work which exec immediately
discards.

huangapple
  • 本文由 发表于 2023年3月7日 12:52:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658157.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定