如何编辑损坏的bash配置文件 [英] How to edit corrupted bash profile

查看:160
本文介绍了如何编辑损坏的bash配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我导出了我的bash配置文件中不正确的PATH,并且我无法再打开它来对其进行编辑.更糟糕的是,由于这个原因,我的终端基本上完全坏了.

I exported a PATH that is incorrect in my bash profile, and I can no longer open it to edit it. Even worse, my terminal is basically completely broken because of this.

如果我运行vim ~/.bash_profile

我收到以下错误:

-bash:vim:找不到命令

-bash: vim: command not found

-bash:sed:找不到命令

-bash: sed: command not found

如果我尝试使用类似ls的命令,则会得到:

If I try to use a command like ls I get:

-bash:ls:找不到命令

-bash: ls: command not found

-bash:sed:找不到命令

-bash: sed: command not found

如果我什至无法编辑我的bash个人资料,该如何解决?

How can I fix my bash profile if I can't even edit it?

推荐答案

您终端没有损坏,因为它是使用此破PATH变量,它已保存在〜/.bash_profile中的bash只是丢失.因此,当您重新加载(源)配置时,bash只是从相同的损坏的PATH中重新读取.

Your terminal isn't broken, bash is just lost because it is using this broken PATH variable, which you have saved in ~/.bash_profile. So, when you reload (source) your configuration, bash is simply re-reading from the same broken PATH.

要修复此问题,必须编辑配置或替换文件.

To fix it, you must either edit the configuration or replace the file.

同时,您可以从命令行针对当前Shell会话临时(可能)还原默认PATH: PATH="/bin:/sbin:/usr/local/bin:/usr/bin:/usr/sbin:"

否则,您必须包括输入的每个命令的完整路径(如上所述),因为bash不再知道要为这些程序(命令)查找的目录.

Otherwise, you must include the full path to each command you enter (as commented above) since bash no longer knows which directories to look in for these programs (commands).

尝试使用/usr/bin/vim ~/.bash_profile打开文件进行编辑. 如果您想删除文件,请尝试:/bin/rm ~/.bash_profile但不要忘记替换它!

Try /usr/bin/vim ~/.bash_profile to open the file for editing. If you'd like to instead remove the file, try: /bin/rm ~/.bash_profile But don't forget to replace it!

成功,编辑或替换文件后,您需要提供该文件的源,以便将其与bash的每个新实例一起加载:. ~/.bash_profile.

Once you've successfully, edited or replaced the file, you need to source it for it to be loaded with each new instance of bash: . ~/.bash_profile.

此外,最好将您的配置放置在~/.bashrc文件中,尽管这不会阻止相同情况的发生.

Also, it is better to place your configuration in the ~/.bashrc file, though this would not have prevented the same situation from happening.

这篇关于如何编辑损坏的bash配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆