如何列出包括 LD_LIBRARY_PATH 在内的所有 Linux 环境变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21122303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:51:26  来源:igfitidea点击:

How to list all Linux environment variables including LD_LIBRARY_PATH

linuxubuntucentos

提问by Michael harris

How to list all the environment variables in Linux?

如何列出Linux中的所有环境变量?

When I type the command envor printenvit gives me lots of variables, but some variables like LD_LIBRARY_PATHand PKG_CONFIGdon't show up in this list.

当我输入命令时envprintenv它会给我很多变量,但有些变量喜欢LD_LIBRARY_PATHPKG_CONFIG没有出现在这个列表中。

I want to type a command that list all the environment variables including this variables (LD_LIBRARY_PATHand PKG_CONFIG)

我想输入一个命令,列出所有环境变量,包括这个变量(LD_LIBRARY_PATHPKG_CONFIG

采纳答案by Maxim Egorushkin

envdoes list all environment variables.

env确实列出了所有环境变量。

If LD_LIBRARY_PATHis not there, then that variable was not declared; or was declared but not exported, so that child processes do not inherit it.

如果LD_LIBRARY_PATH不存在,则未声明该变量;或已声明但未exported,因此子进程不会继承它。

If you are setting LD_LIBRARY_PATHin your shell start-up files, like .bash_profileor .bashrcmake sure it is exported:

如果你LD_LIBRARY_PATH在你的 shell 启动文件中设置,像.bash_profile.bashrc确保它被导出:

export LD_LIBRARY_PATH

回答by sager89

try

尝试

export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}

This will modify the variable.

这将修改变量。

To print it, type: echo $LD_LIBRARY_PATHand it should show the above value.

要打印它,请键入:echo $LD_LIBRARY_PATH它应该显示上述值。

If you're seeing nothing when you print that, then the variable might not be set.

如果您在打印时什么也没看到,则可能未设置该变量。

回答by BMW

The question in fact is a good question. when run envor printenv, the output will be the system environment, but LD_LIBRARY_PATH is not belong to.

这个问题其实是个好问题。运行env或 时printenv,输出将是系统环境,但 LD_LIBRARY_PATH 不属于。

For example, if you set a=1, you can't show it by env. Same as LD_LIBRARY_PATH, it is used by ld.so only(ld. so – this little program that starts all your applications)

例如,如果您设置了a=1,则无法通过 显示它env。与 LD_LIBRARY_PATH 相同,它仅由 ld.so 使用(ld.so - 这个启动所有应用程序的小程序)