Accidentally wiped out PATH definition in Bash shell - bash

I created a.bash_profile and defined
export PATH=/user/local/bin
rather than
export PATH=/user/local/bin:$PATH
Then, I ran
source ~/.bash_profile
Now none of the command, e.g., ls works. Is there a way to back out this change? Thank you.

If you have fixed your .bash_profile file, you just restart bash to get your $PATH back. If that's not an option, or you can't fix the file externally, you can do export PATH="/bin:/usr/bin:/usr/local/bin", which should give you enough to get to vi or some other text editor so you can fix your .bash_profile, then you can restart bash.

Related

echo $PATH not reflecting saved paths

I have attempted to add, export PATH="$PATH:/Users/My_Name/desktop/My_Folder", to .bash_profile, .bashrc, and .profile. I executed the command source ~/.bash_profile, source ~/.bashrc, and source ~/.profile to refresh the $PATH and it does reflect that when I execute echo $PATH.
However, when I open a new terminal and execute echo $PATH it is unchanged.
The issue is my system (macOS Big Sur) will not recognize the updated $PATH when I open a new terminal unless I execute the source command every time to refresh my $PATH.
For context, I edited all three because I have scoured multiple sites for suggestions and have exhausted all my options.
Solution: I realized that I was using zsh. To change I executed chsh -s /bin/bash to change my shell to bash.
Solution: I realized that I was using zsh. To change I executed chsh -s /bin/bash to change my shell to bash.
You need to open your .profile file in an editor like nano or pico and make sure your command is at the bottom of the file. Also, make sure you close your quotes like this:
export PATH="$PATH:/Users/My_Name/desktop/My_Folder"
You might also consider placing the new path at the front like this:
export PATH="/Users/My_Name/desktop/My_Folder:$PATH"
I have an alias in my profile folder called reBASH looks like this
alias reBASH='source ~/.bash_profile'
So that when I change .bash_profile, I merely type reBASH, hit enter and it gets applied to the current session ... just something you might consider as a convenience when doing things like this.

I have to run source ~/.bash_profile every time in order to see react-native

I added a bunch of aliases to my .profile file. None of them work either.
My .bash_profile has one line: export PATH="$HOME/.npm-packages/bin:$PATH"
I went as far as creating a .bashrc file and putting source ~/.bash_profile in it.
Nothing I have tried is working, other than if I put source ~/.bash_profile into my shell every time I open a new one.
I have tried every stack overflow answer I could find and nothing is working.
Anyone out there can help me?
I am on mac, using fish, but same results in bash.
Fish is not, in general, bash compatible. That means it won't read bash's configuration files and if source works on them that's lucky (e.g. export var=val will work, var=val will not).
You need to either start fish from bash (and have all necessary variables exported), rewrite the necessary configuration for use with fish and add it to config.fish, or use something like https://github.com/edc/bass to read bash's changed environment from fish.

Change CDPATH permanently

I am using Linux Mint 16 with xfce and I have the following problem:
For my work I always have to switch to a long path in my File system.
I tried to avoid this by adding this one particular folder to my CDPATH.
I added the path with:
export CDPATH=$CDPATH:/directory/to/add
But this only works for one terminal session. After closing the terminal, the CDPATH is gone again.
I have read to put the given line for exporting into my .bashrc or my .profile or some other files, but none of them worked permanently.
So, how can I add a directory to my CDPATH permanently ?
Maybe with a bash Script in my autostart ?
Add it in ~/.bash_profile, if you want to use it in a non-login session then add it in ~/.bashrc
Here is a explanation for the difference between them.

MacOS source ~/.bash_profile disabled everything

So I was trying to setup the Go programming environment on my Mac and add the necessary directory to the path by modifying the .bash_profile accordingly. After saving the .bash_profile, I tried running "go version" for example but it still didn't work.
After a bit of searching I found that if i did the following:
source ~/.bash_profile
The go version would work. Which it does but it seems that my PATH has been changed since commands such as: nano, vi, ls, sudo etc do not work anymore.
Is there a way of recuperating my initial environment PATH?
Thanks in advance!!
:D
PS - let me know if my issue is not clear
Note that your path is likely just "broken" for your current shell session: Mac OS X doesn't strictly use .bash_profile for your PATH.
My guess is that you didn't write out export PATH=$PATH:$GOPATH/bin and export GOPATH=/Users/sSmacKk/go/ (or wherever you wanted to set it) correctly: if you forget to assign the existing path back to your new path, you'll have problems.
Run path_helper from /usr/libexec/path_helper (which would normally be on your path!)
Add the lines: export GOPATH=/wherever/you/want/ and then export PATH=$PATH:$GOPATH/bin to your .bash_profile
Save and exit from your text editor and then source .bash_profile.

In Mac OSX 10.5, it can't find my Terminal commands sudo, find, etc

I don't know what has happened, but in my Terminal on Mac OSX 10.5 it can no longer find my sudo command, or find command, etc. They are there because if I put /usr/bin/sudo or /usr/bin/find it works fine...
My .bash_login file looks like this:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin$PATH"
My .bash_profile file looks like this:
export PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:/Library/Python/2.5/site-packages/django_trunk/django/bin:/usr/local/mysql/bin:/usr/bin/sudo$PATH"
I'll say now, I don't really know what I'm doing with the Terminal. I'm just a beginner to it all, and I must of done something for the environment variables (is that what they're called?) to be lost. I presumed I'd just have to make sure the /usr/bin/ path is in my bash files, but they are, and it doesn't seem to work. Please help!
Also, when I do use the /usr/bin/find command, it says "Permission denied" to me, even though I am logged into Mac OSX as the System Administrator account. I don't understand.
Any help would be grand. Thank you - James
It looks like both of your PATH exports are malformed:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin$PATH"
The end bit there won't work. It should be:
export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:$PATH
Notice the colon before '$PATH'? It's important ;)
Also, the double quotes are not necessary.
If this doesn't work, we will need more information. It is possible that something else is modifying your path even after your shell configurations are loaded.
Can you post the results of:
$ echo $PATH
Configuration files are not always a good indication of the current environment variables, since they are modified by many programs and files, all across your system. To see all of your environment variables, you can run:
$ env
This should fix the problem completely and permanently.
first, export environment paths by using below command in the terminal.
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/b‌​in
now you have the commands you want. (eg. try ls. You'll see the command is working). But this is only for the current session. If you close the terminal and open a new one, you will have the previous issue. To make this change permanent, use below command,
go to home directory
cd ~
open .bash_profile file in nano / vim (I'm using nano here)
nano .bash_profile
This will open up nano editor. In a new line, paste the following;
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:$PATH
press 'control'+'o' to save (WriteOut) and 'control'+'x' to exit nano.
All done ! Now try the commands.
Check out --- http://www.sweeting.org/mark/blog/2008/05/26/mac-os-x-tip-setting-path-environment-variables
I went trough the same issue and here is how I solved it.
First of all I reverted the file to its original doing this way
/usr/bin/nano ~/.bash_profile
In my case I was not able to make work any command alias. Even vi or vim didnt work without specifying the full path of that command.
If nano is not installed just replace nano in the command by the editor installed
After that just restart the computer. In my case as I said bellow I could not use any command. When trying to do /usr/bin/source ~/.bash_profile
that command failed. So I had to restart the OS and it worked

Resources