Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the colon do in PATH

Tags:

bash

terminal

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?

like image 382
Kabe Lee Avatar asked Mar 02 '16 02:03

Kabe Lee


People also ask

What does colon do in CMD?

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.

What does colon in HTTP request mean?

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.

How does a path work?

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.

Are colons allowed in urls?

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.


2 Answers

: 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
  • /
like image 124
slashfoo Avatar answered Sep 20 '22 07:09

slashfoo


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

like image 20
cdarke Avatar answered Sep 20 '22 07:09

cdarke