6

Here I found the file with ..:; name. mkdir '..:;' worked fine. But in PATH directory names are split by :. How to add this directory to PATH?

1

2 Answers 2

9

The POSIX standard explicitly mentions that it's impossible to use directories with : in their names in the PATH variable's value.

See the entry about the PATH environment variable in the section entitled Other Environment Variables:

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


In the zsh shell, you would be able to add the directory to your search path and have it work as expected by modifying your path array variable (which is tied to PATH):

path+=( '/some/path/..:;' )

or to add the entry first rather than last:

path=( '/some/path/..:;' $path )

However, after doing this, modifying the shell's search path using PATH rather than via the path array will cause the ..:; entry to be split on the :. Also, note that although the modified path may work in the zsh shell, it is unlikely to work as expected in another shell or in an application started from that shell.

2
  • To prepend an element to an array in zsh, you can also do: path[1,0]=(element) Commented Jul 15, 2022 at 9:30
  • 1
    The $path trick seems to also work in tcsh (the $PATH tied to $path was borrowed from csh), not in fish where $PATH is some sort of magic array. PATH=(dir:with:colon) seems to work in yash as well. Commented Jul 15, 2022 at 9:33
4

According to this answer on StackOverflow, it is impossible because $PATH is not interpreted by the shell, but by execvp which doesn't provide for escaping the separator character.

1
  • 1
    I don't expect many shells will use execvp() from the libc as they'll likely want to construct the envp[] array passed as the 3rd argument to execve() by themselves (based on the shell variables marked for export). Commented Jul 15, 2022 at 10:46

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.