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!
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.
PATH
is an environment variable that specifies directories to be searched (in order from left-to-right) to find executables. When you invoke something likegzip
, the$PATH
environment variable is split on:
and each of those paths is searched to see if it containsgzip
.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.
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: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
orenv | grep PATH
to see what that variable looks like.