I am new to bash, and I saw people often add :
after a directory when modifying PATH
. After searching for a while, I did not find an answer for that, or I believe I did not search it correctly. So I hope I could get an answer here.
Example:
/Users/chengluli/anaconda/bin:/Users/chengluli/.rbenv/shims:/
What does the :
after bin
and shims
do?
It is used when a command is needed, as in the then condition of an if command, but nothing is to be done by the command.
No special meaning. The colon is just an allowed character in the path, just like the other characters in the path are. How they are interpreted is up to the server.
PATH contains a string of directories separated by colons. The way that PATH is used is that any executable files in the directories listed in PATH can be executed without specifying the full path to the file.
Yes, unless it's in the first path segment of a relative-path reference. So for example you can have a URL like this: https://en.wikipedia.org/wiki/Template:Welcome.
:
is the separator. The PATH
variable is itself a list of folders that are "walked" through when you run a command.
In this case, the folders on your PATH
are:
/Users/chengluli/anaconda/bin
/Users/chengluli/.rbenv/shims
/
As others have said, the :
is a separator (Windows uses a semi-colon ;
). But you are probably thinking of a trailing colon :
at the end of the PATH
variable. For example:
/Users/chengluli/anaconda/bin:/Users/chengluli/.rbenv/shims:
From the bash man pages:
A zero-length (null) directory name in the value of PATH indicates the current directory. A null directory name may appear as two adjacent colons, or as an initial or trailing colon.
Putting the current directory in the PATH is generally considered a security risk and a bad idea. It is particularly dangerous when using the root user.
By the way, bash only uses $PATH on the first call of an external program, after that it uses a hash table. See man bash
and the hash
command
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With