如何在 Mac OSX Snow Leopard 上修复 bash 中的路径变量

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

How to fix path variable in bash on Mac OSX Snow Leopard

linuxmacosbashterminal.profile

提问by Adam

This might be a noob question, but I need help. I screwed up my terminal by trying to alter my path variable using the following command:

这可能是一个菜鸟问题,但我需要帮助。我尝试使用以下命令更改我的路径变量,从而搞砸了我的终端:

$ sudo nano .profile

$ sudo nano .profile

Before I did that, if I were to type: $ echo $PATH

在我这样做之前,如果我要输入: $ echo $PATH

I would get: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

我会得到: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

When I opened .profile in nano it told me that the file didn't exist. I figured that made sense, since I had never edited this file before. I proceeded to enter a path to a directory I was using for a php framework and saved the file.

当我在 nano 中打开 .profile 时,它​​告诉我该文件不存在。我认为这是有道理的,因为我以前从未编辑过这个文件。我继续输入我用于 php 框架的目录的路径并保存文件。

After I saved the file, I noticed that none of my bash commands are working. Now I can't do anything from the terminal. I can't even edit .profile in nano because it says -bash: nano: command not found

保存文件后,我注意到我的 bash 命令都不起作用。现在我不能从终端做任何事情。我什至无法在 nano 中编辑 .profile 因为它说-bash: nano: command not found

I'm clearly new to working with the terminal. I feel completely lost. Please provide some guidance on how to restore the terminal to working condition.

我显然不熟悉使用终端。我觉得完全迷失了。请提供一些有关如何将终端恢复到工作状态的指导。

回答by Yuji

Use absolute paths.

使用绝对路径。

 $  /usr/bin/sudo /usr/bin/nano .profile

If you add something to a path, never just do

如果你在路径上添加一些东西,永远不要只是做

 PATH=/path/to/something

instead do

而是做

 PATH=$PATH:/path/to/something

By the way, you shouldn't/don't have to use sudoto edit your own file, such as .profile. Use sudoonly when you need to edit the file which doesn't to belong to your account.

顺便说一句,您不应该/不必使用sudo来编辑您自己的文件,例如.profile. sudo仅在您需要编辑不属于您帐户的文件时使用。

回答by pacoguevara

I had the same problem! The way I solved was writing the follow command in the terminal: PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/usr/local/git/bin:/usr/X11/bin

我有同样的问题!我解决的方法是在终端中编写以下命令:PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/usr/local/ git/bin:/usr/X11/bin

Hope it can be useful for you

希望对你有用