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 exe file (called "deadbeef") with appropriate exe rights, which path 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 to the
/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 will be in a 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 which and type commands tells, that exe file is existed in both case.
So what's the problem??? Why bash process the apostrophes like this?

- 21
- 5
3 Answers
Apostrophes are special character for almost all shells (shell is the term that refers to command line interpreters, which is the program that reads what you type and co the appropriate thing).
Short answer : don't do that. As the case for spaces, better avoid filenames with special meaning or special chars in them.
Long answer: if you want to use apostrophes, you have to "quote" them (using special characters that stop the shell from interpreting them). Autocompletion will quote them automatically when needed... Example:
(0)samsung-romano:~/tmp/try% touch "hard'n'soft"
One way of quoting single quotes is with double quotes. (And viceversa, although is more complex than this).
(0)samsung-romano:~/tmp/try% ls
hard'n'soft
Now if it write cat hard
and press TAB
:
(0)samsung-romano:~/tmp/try% cat hard\'n\'soft
Backslashes are another form of quoting the following character.

- 31,947
-
Thank you for answer, it's all clear about preventing shell to interpret special symbols, when trying to just type it, like using touch, ls and stuff. There is no problem, I use it with my hard'n'sofr dir every day without stumbling. But my question related to the $PATH and autocompletion - I just want to know, why in this exact situation bash cannot complete command, though it sees the exe file, when I use path with apostrophes. – mallniya Feb 03 '14 at 23:09
Well, as bash_completion team advised, I have reported this behaviour to bash team and their answer is:
"Thanks for the report. This will be fixed in bash-4.3."
looks like the bug is already known and we should just wait.

- 21
- 5
In order to expand a path with apostrophes in it, add an " in front of the path.
cd "/home/mallniya/hard
expands without problems in tab-expansion.

- 2,750