Strange autocompletion behavior in bash (Linux) using PATH variable with special symbol - apostroph (')

StackOverflow https://stackoverflow.com/questions/21638465

Question

Well...I'm so confused, cause the only real problem in my case is freaking apostrophe (').
Situation: expanding PATH variable influence word completion, based on whether was apostrophes in additional path or not.
Example: I have an executable file (called deadbeef) with appropriate executable rights, the path to which contains 2 apostrophes:
/home/mallniya/hard'n'soft/soft/gnu-linux/portable/deadbeef-0.6.0
Specialy for an experiment I put the same file into to another directory:
/home/mallniya/hardnsoftaa/soft/gnu-linux/portable/deadbeef-0.6.0
If I export first path to the variable PATH there will be no autocompletion in bash, but there will be in the second case. When I type in terminal first letters of program in exported directory
dead[TAB]
There is no completion in first case, but when I use TAB with the same word in second condition - it works.
But if I type command deadbeef in first case manually - it also executes.
Moreover, both whichand type commands tell, that the executable file is exists in both cases.
So what's the problem?

note:
I heard about links, using names without special symbols and other solutions for get thing simply working - I have no interest in it and just wonder: if I really have to use special symbol like this in PATH variable in the future, what could I do, to make autocompletion work? Is it a bug? And if yes - what exactly goes wrong?

Was it helpful?

Solution

It's a long-standing bug in bash. See this thread on the bug-bash mailing list. (As indicated in the thread, the bug was reported in 2008 as a problem with bash-completion scripts, but it is actually a problem in bash itself.)

OTHER TIPS

Apostrophes are special characters to the shell used to tell bash to (amongst other things) not parse special characters such as $, !, or \. If you have a directory with a ' in its name, and you want it to be in your PATH, you need to escape them with backslashes, e. g. .../hard\'n\'soft/....

It is for reasons like this that it is strongly discommended to have spaces, quotes, or other special characters in your file or directory names.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top