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?
2 Answers
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 inPATHshould 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.
-
To prepend an element to an array in zsh, you can also do:
path[1,0]=(element)Stéphane Chazelas– Stéphane Chazelas2022-07-15 09:30:29 +00:00Commented Jul 15, 2022 at 9:30 -
1The
$pathtrick seems to also work intcsh(the$PATHtied to$pathwas borrowed from csh), not infishwhere$PATHis some sort of magic array.PATH=(dir:with:colon)seems to work inyashas well.Stéphane Chazelas– Stéphane Chazelas2022-07-15 09:33:29 +00:00Commented Jul 15, 2022 at 9:33
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.
-
1I don't expect many shells will use
execvp()from the libc as they'll likely want to construct theenvp[]array passed as the 3rd argument toexecve()by themselves (based on the shell variables marked for export).Stéphane Chazelas– Stéphane Chazelas2022-07-15 10:46:29 +00:00Commented Jul 15, 2022 at 10:46