Linux 从 LD_LIBRARY_PATH 中删除条目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9754268/
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-06 05:14:35  来源:igfitidea点击:

Removing entries from LD_LIBRARY_PATH

linuxshared-libraries

提问by Robin92

I'm experimenting with Linux shared libraries and added an entry (export LD_LIBRARY_PATH=/path/to/library:${LD_LIBRARY_PATH}) to $LD_LIBRARY_PATH. Now I wish it gone. How can I do that?

我正在试验 Linux 共享库,export LD_LIBRARY_PATH=/path/to/library:${LD_LIBRARY_PATH}并向$LD_LIBRARY_PATH添加了一个条目 ( ) 。现在我希望它消失了。我怎样才能做到这一点?

PS. Typing echo $LD_LIBRARY_PATHbefore I added an entry gave me an empty line. Now it says:

附注。echo $LD_LIBRARY_PATH在我添加条目之前打字给了我一个空行。现在它说:

path/to/library:

路径/到/库:

采纳答案by sirgeorge

If previously it gave you empty line it (most probably) means that the variable was not set (by default it is not set), so you can just unset it:

如果之前它给了你空行,它(很可能)意味着变量没有设置(默认情况下它没有设置),所以你可以取消设置它:

unset LD_LIBRARY_PATH

A few other options to experiment:

其他一些实验选项:

export MY_PATH=/my/path
export MY_PATH2=/my/path2
export LD_LIBRARY_PATH="${MY_PATH}:${MY_PATH2}"
echo $LD_LIBRARY_PATH
/my/path:/my/path2

Removing path from the end:

从末尾删除路径:

export LD_LIBRARY_PATH="${LD_LIBRARY_PATH/:${MY_PATH2}/}"
echo $LD_LIBRARY_PATH
/my/path

Similarily, removing path from the beginning (if set as above):

同样,从头开始删除路径(如果设置如上):

export LD_LIBRARY_PATH="${LD_LIBRARY_PATH/${MY_PATH}:/}"

回答by Carl Norum

Assuming you're using bash, you can set it back to an empty path using:

假设您正在使用bash,您可以使用以下方法将其设置回空路径:

export LD_LIBRARY_PATH=""

And if you want to un-export it:

如果您想取消导出它:

export -n LD_LIBRARY_PATH

The bash man pageis a great piece of documentation to help out with this kind of problem.

bash的手册页是一个伟大的一块文档帮忙的这样那样的问题。