What does // and :: in the values of environment variables mean?
Solution 1
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.
Solution 2
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/jon.kiparsky/bin::::::/home/jon.kiparsky/bin::/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
did not break my path! :)
Roman
Updated on September 18, 2022Comments
-
Roman over 1 year
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
andccc
. Is it just a mistake that is interpreted as a single slash or it has a special meaning?