英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论