简体   繁体   English

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

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

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

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. 当我在nano中打开.profile时,它告诉我该文件不存在。 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. 我继续输入到我用于php框架的目录的路径,并保存了文件。

After I saved the file, I noticed that none of my bash commands are working. 保存文件后,我注意到我的bash命令均无法正常运行。 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 我什至无法编辑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. 请提供有关如何使终端恢复工作状态的一些指导。

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 sudo to edit your own file, such as .profile . 顺便说一句,您不必/不必使用sudo来编辑自己的文件,例如.profile Use sudo only when you need to edit the file which doesn't to belong to your account. 仅在需要编辑不属于您帐户的文件时才使用sudo

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 希望对您有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM