1

For bash the path separator for the environment variable $PATH is ":"

So out of curiosity:

if a have a directory named $HOME/with:character

Is there any way I can add it to the search path?

Please note that I think adding : to a filename is not a very smart idea, but I wanted to know if I could add such a directory to a search path if I ever encountered one

I tried with a backslash, but this doesn't seem to work:

export PATH="$PATH:$HOME/with\\:character"

double : (::) doesn't work either

gelonida
  • 455

1 Answers1

3

There is no way to escape the colon. This is impossible according to the POSIX standard. PATH handling is done within the execvp function in the C library where there is no provision for any kind of quoting. This is the reason why including characters not in the portable filename character set is strongly recommended against.

From SUSv7:

Since <colon> is a separator in this context, directory names that might be used in PATH should not include a <colon> character.

See also source of GLIBC execvp. It uses the strchrnul function for processing the PATH components, with no unescaping of any kind.

Your best bet is to rename the directory. If it really needs to have that name, you can create a symbolic link and add that to your $PATH:

 $ cd /path/to/add
 $ ln -s a:b a_b
 $ PATH="$PATH:/path/to/add/a_b/bin"
harrymc
  • 498,455