What does the command export PATH=$PATH:~/bin
accomplish?
I would like to understand this more than I already do; please assist!
What does the command export PATH=$PATH:~/bin
accomplish?
I would like to understand this more than I already do; please assist!
PATH
is an environment variable that specifies directories to be searched (in order from left-to-right) to find executables. When you invoke something like gzip
, the $PATH
environment variable is split on :
and each of those paths is searched to see if it contains gzip
.
It is common to prepend directories to this variable, so that they are searched before the existing (default) locations. This is generally done when you want to add a non-standard directory to the PATH, so that you can install applications to subdirectories.
export PATH=$PATH:~/bin
This appends ~/bin
(i.e. "$HOME/bin") to the PATH, so that you can execute scripts/binaries from the "bin" folder in your home directory.
You can determine which command will be executed from your PATH by using the which
command. For example:
-bash$ which gzip
/usr/bin/gzip
You can also drop the export
keyword, but in doing this, the changed PATH variable will not be visible to scripts invoked from your bash shell.
Take a look at the output of echo $PATH
or env | grep PATH
to see what that variable looks like.
It modifies the current setting of the PATH
environment variable and (re)exports it.
The change is to add ~/bin
to the PATH
so it will, as a last resort, look in the bin
directory under your home directory (specified by $HOME
, which is normally but not necessarily the same as your login directory as specified in the password database and identified by ~username
) for a command. This means that there's an extra place to search for commands.
Personally, I put my bin
directory at the front of my PATH
; my commands override other people's commands.
export PATH=$PATH:~/bin
will append ~/bin
to your current $PATH
in your current shell.
If you put it in one of your shell's init files, such as ~/.bashrc
for bash
, you could add ~/bin
to your $PATH
permanently.