Today I experienced a panic attack when I edited my path variable and removed all the content from the $PATH by mistake. This might happen to any one, because we are humans and we often tend to make some stupid mistakes for which we do regret later. But this does have a small solution to undo the problem. You can reset the $PATH variable to the default position.
Let me first tell you what happens if you remove the existing path from the $PATH variable. One cannot use any of the commands in the terminal. Simple commands like open, clear, vim, touch nothing works. You cannot access the development packages through the terminal like python interpreter, java, gcc. Without these basic commands, a developer cannot survive. So, always be careful when you are going to edit your $PATH variable so that you don’t face any problems in the future.
Coming to the hack:
Obviously when you edit the /.bash_profile or /.profile file, you might have used the text editor like TextEdit or emacs or any other editor.
So, go to the application which you have used to edit the above files and go to file menu and open the /.bash_profile or /.profile file from the recent menu.
After opening it, reset the path to its default by typing export PATH=/usr/bin:/usr/sbin:/bin:/sbin and save the file.
Open Terminal and run the command source ~/.bash_profile which will make the changes immediately.
Check the $PATH variable’s value by running echo $PATH. It should flash the /usr/bin:/usr/sbin:/bin:/sbin
To confirm that your path has been reset properly. Type in the basic commands and check if they are working properly.
Note: Do not put any quotes around the path while you are editing it in the text editor.