I have a function which is supposed to remove duplicate copies of directories from my
PATH environment variable. I have created some duplicates so I can test it but I don't know how to:
1) put the script in the
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
Just edit the
.bashrc file (better make a copy of the original first, just in case) and simply add a line the name of the script you want to execute to the file (at the bottom of the
.bashrc would be fine).
If the script is not in your home directory, be sure to specify the complete path.
The right file for environment variables such as
PATH is not
.bashrc is a configuration file for interactive shells;
.profile is the session startup script. See Is there a ".bashrc" equivalent file read by all shells?.
Bash is a bit peculiar with its startup files: in login shells, it reads
~/.bash_profile if it exists and
~/.profile otherwise. In interactive non-login shells, it reads
~/.bashrc. There's no reason not to load interactive settings in interactive login shells, and there are many setups where the session start shell is not invoked as a login shell but
~/.profile is read explicitly. So make your
~/.bash_profile contain just these two lines:
. ~/.profile case $- in *i*) . ~/.bashrc;; esac
If you had things in
~/.bash_profile, move them to
~/.profile if they are things like environment variable settings, and to
~/.bashrc if they are interactive shell configuration such as aliases and key bindings.
Put all your
PATH manipulation in