What does // and :: in the values of environment variables mean?

On my Linux machine some of the environment variables contain lists of directories. The directories are separated by :. But sometimes they are separated by ::. Is it just a mistake that should be treated as : or it means that and empty string is one of the directories (that probably should be interpreted as the current directory).

Most of the directories specified in the environment variables have this format:

/aaa/bbb/ccc

However, some of them have this format:

/aaa/bbb//ccc

Note double slash between bbb and ccc. Is it just a mistake that is interpreted as a single slash or it has a special meaning?

0

2 Answers

The double-colon (::) does indeed mean the current directory. The Bash manual describes PATH as:

A colon-separated list of directories in which the shell looks for commands. 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.

But personally, I think it's better to explicitly specify the current directory (e.g., /foo/bar:.) for clarity.

As for the slashes, any number of adjacent slashes is treated as a single slash.

multiple '/' separators are ignored:

$ cd .////somedir

is equivalent to

$ cd somedir

As for the extra separators in your PATH, a little experimentation suggests that they are also ignored.

At least, this:

/home/jon.kiparsky:2040 $ echo $PATH
/home/

did not break my path! :)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like