How to edit corrupted bash profile

谁说我不能喝 提交于 2019-12-18 09:48:57

问题


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.

If I run vim ~/.bash_profile

I get the following errors:

-bash: vim: command not found

-bash: sed: command not found

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

-bash: ls: command not found

-bash: sed: command not found

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


回答1:


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.

In the meantime, you can restore (what is likely) your default PATH temporarily, for the current shell session, from the command-line: PATH="/bin:/sbin:/usr/local/bin:/usr/bin:/usr/sbin:"

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).

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!

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.

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



来源:https://stackoverflow.com/questions/39795766/how-to-edit-corrupted-bash-profile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!