Issue running through 'Adding ~/bin to $PATH in Bash' when setting up cli on linux

So running through the tutorial I ran ‘echo ‘export PATH=~/bin:$PATH’ >> ~/.bash_profile’
and it wiped my $PATH environment, i restored it but just wanted to let someone know that this could mess up others terminals for those that don’t know too much about it or how to restore it.
I suggest to instead edit the files in a editor like gedit or nano.

I’d like to dig into this further. Some questions:

  • did you have a pre-existing ~/.bash_profile file?
  • did you have a pre-existing ~/.profile file?
  • in what file do you currently customize your PATH?
  • what is your PATH?

That command should only prepend to the PATH, not remove anything from it. It should be safe to run. Without further details it’s hard to know where things went wrong here.

All my files were default i believe, i personally never made changes to them. I used .bashrc file and this is whats in my PATH:
/home/zevian/bin:/home/zevian/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/zevian/.dotnet/tools

yeah i thought so too, but after running source on the file then trying nano to check the file and returned that nano was not in path, ls wasn’t working either. I ran echo $PATH and only had ~/bin instead of the default full list.

This is my system specs if that helps:

OS: Kali GNU/Linux Rolling x86_64
Kernel: 6.6.15-amd64
Shell: bash 5.2.21
DE: Plasma 5.27.10
CPU: 12th Gen Intel i7-12700K (20) @ 4.900GHz
GPU: NVIDIA GeForce RTX 3060 Ti Lite Hash Rate
Memory: 4729MiB / 31840MiB

I can’t find where this is written. Can you point me to this step?

Found it:

From https://exercism.org/cli-walkthrough, click these buttons

  • Linux
  • Using the source code
  • Continue
  • Yes

@Grandilex looking in your home directory, which of these files exist?

  • .bash_profile
  • .bash_login
  • .profile

I have all of them, sorry for late reply i got busy. I’ll try and replicate the issue in a few hours

I wonder if one of the files only sets PATH if PATH is not already set.

A login shell reads one of them in the order I specified: first one wins, the rest are ignored (by bash – .profile may be used by other *nix processes)

ref: 6.2 Bash Startup Files

@glennj
I have no idea how my files were setup beforehand, but now i can’t reproduce the issue. I just remember after running
echo 'export PATH=~/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
I ran nano and returned error saying nano was not in my /bin,
checked my .bashrc and it was empty except for export PATH=~/bin:$PATH. Had to load the backup onto it and got it working.

Did you maybe run echo 'export PATH=~/bin:$PATH' > ~/.bashrc with one > vs >>?

One thing I have in my bash configuration is set -o noclobber

That prevents > redirection from obliterating files:

$ touch newfile
$ echo hello > newfile
bash: newfile: cannot overwrite existing file

And if I really want to do that, the >| redirection lets me.

$ echo hello >| newfile
$ cat newfile
hello

I possibly did, but was still able to use nano just now.