bash 从环境变量中删除路径

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

Remove path from environment variables

macosbash

提问by Ramy Al Zuhouri

For mistake I have added a path that I don't want to use.
I have create a file named .base_profile, exported the path using the command source .base_profile, but I don't need this path, how to delete it?

由于错误,我添加了一个不想使用的路径。
我已经创建了一个名为.base_profile 的文件,使用source .base_profile 命令导出了路径,但是我不需要这个路径,如何删除它?

Maybe the title wasn't so appropriate, but I haven't modified the PATH variable.
I have written this in the .base_profile file:

也许标题不太合适,但我没有修改 PATH 变量。
我在 .base_profile 文件中写了这个:

export MP=$MP/usr/local/mysql/bin

And then used the source command.The problem is with the MP variable, which is not one that I want, it's too long.I want to delete it, how to do it?

然后用source命令。问题是MP变量,不是我想要的,太长了。我想删除它,怎么办?

采纳答案by user unknown

Do an

做一个

echo $PATH

Then grab with the mouse that part, which looks useful, and append it to:

然后用鼠标抓住那个看起来有用的部分,并将其附加到:

PATH=

So for example - not on an OSX-System:

例如 - 不在 OSX 系统上:

PATH=/home/ramy/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

If you only sourced the path in one terminal, you can, alternatively, open a new terminal.

如果您只在一个终端中获取路径,您也可以打开一个新终端。

If you added the source-command to one configuration script, you have to remove it there, to get rid of it permananetly.

如果您将 source-command 添加到一个配置脚本中,则必须在那里将其删除,以永久删除它。

回答by glenn Hymanman

The way to restore your path to the default is PATH=$(getconf PATH)

恢复默认路径的方法是 PATH=$(getconf PATH)

回答by pizza

Fix your errors in the file, and fix the env var with

修复文件中的错误,并修复环境变量

export PATH=[the correct one]

export PATH=[正确的一个]