Skip to content

Instantly share code, notes, and snippets.

@TheBrotherFromASouthernMother
Last active March 15, 2019 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheBrotherFromASouthernMother/c0d25b6376065cbc490dcdadbbee5ae4 to your computer and use it in GitHub Desktop.
Save TheBrotherFromASouthernMother/c0d25b6376065cbc490dcdadbbee5ae4 to your computer and use it in GitHub Desktop.
Unborking your bash_profile

In my time as an engineer at Change.org I have had to become much more familiar with the command line than I ever thought would be neccessary. Adding variables, secrets passcodes, and api keys to my .bash_profile has become incredibly commonplace in my day-to-day, and all of that has required that I get comfortable using my terminal.

However, despite my growing familiarity with the command line, every once in a while I'll find that I've made a massive mistake (Life of a software developer, am I right?). I'll be going about my day and find out that suddenly I've completely screwed up my bash_profile! Maybe it was an invalid char or a mistake in exporting my $PATH variable, whatever it the mistake may be I find out immediately when I attempt to source my bash_profile and get an error.

"Huh" I think to myself, "I suppose I made a mistake adding that last bash script to my bash_profile, I guess I'll just go back and edit it."

Me: nano ~/.bash_profile

My Terminal: -bash: nano: command not found

Me (frantically typing): cat ~/.bash_profile

My Terminal: -bash: cat: command not found

Suddenly my commands aren't working, even worse, according to bash they no longer exist!

I close my terminal and reopen it again only to see the original error message appear again and find that my commands are still lost! The terminal is sourcing my bash_profile with every open so the error will immediately wipe out any commands immediately.

"Oh well" I think to myself dejectedly, "I guess I've destroyed my file system and will never program again"

Maybe you've been in a similar situation, you've completely borked your bash_profile, and seemingly your entire system! Well there's nothing to fear.

(From what I understand): bash is just a simple and handy way of packaging all those commonly used commands together, but screwing up your bash doesn't erase them. They're still on your file system, albiet in disparate locations.

You can access them like so:

/usr/bin/sudo /usr/bin/nano ~/.bash_profile

And suddenly you're able to edit your bash_profile again and get rid of or modify the offending variable that's causing your troubles!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment