bash tabbing for autocompletion escapes $
Asked Answered
E

1

8

In shell (GNU bash, version 4.2.47(1)-release (x86_64-suse-linux-gnu)), when I hit tab for autocompletion, the "$" is escaped after the variable name is completed, but if there is no completion then it just bells. E.g.

$ ls $JDK_H<tab>

results in

$ ls \$JDK_HOME (with a trailing space)

On an old GNU bash, version 3.2.51(1)-release (x86_64-suse-linux-gnu), it did not escape the "$" after completion which is what I would like.

Is there a way to get that old behavior without strong side-effects? My BASHOPTS and SHELLOPTS are:

# (indented for readability)
BASHOPTS=checkwinsize:cmdhist:expand_aliases:extglob:extquote
            :force_fignore:histappend:interactive_comments:login_shell
            :progcomp:promptvars:sourcepath
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history
            :interactive-comments:monitor

Thanks. I am using SLES SP11.

--UPDATE. Other completions seem to work as usual, e.g. cd or echo do not escape the $. I also momentarily commented out /etc/share/bash-completion/bash_completion from my /etc/bash.bashrc which stopped $-escaping. So it appears like some kind of complete config issue.

Efflux answered 8/9, 2015 at 16:42 Comment(5)
Report a bug to SuSE.Fourlegged
I am not certain if this is a bug or a feature :-( I do know it is very frustratingEfflux
Why close? I see an infinite number of shell questions on SO, some indeed version relatedEfflux
The fact that many off-topic questions go unnoticed does not change the rules. This is borderline for several reasons -- if it's a bug, you should be submitting a bug report; it's not directly programming-related; and you are not asking how to solve this in code. I also believe it is a duplicate, although I cannot locate the earlier similar question I saw.According
Sure, np. I see several pointers saying it's a bug. (As an aside, I think of SO as a living ecosystem where what is appropriate use is keeps on getting refined by the community.)Efflux
S
6

Recent bash versions introduced some compatibility issues regarding this. Try like this:

complete -r # temporarily disable all completion rules
shopt -s direxpand

Links to similar problems reported to the bug-bash mail list:

Sunfish answered 9/9, 2015 at 1:55 Comment(4)
I see nothing that's different from my bash 3. I saw see a huge number of configuration under complete; so I momentarily commented out /etc/share/bash-completion/bash_completion from /etc/bash.bashrc and now cd works just like ls etc. so it appears like some kind of complete config problemEfflux
forgot to add, shopt -s direxpand does not change this behaviorEfflux
Updated by adding some links.Sunfish
Thanks for the links and the tip. It claimed the issue was resolved in 4.2.45 but I am running bash 4.2.47 and still see it.Efflux

© 2022 - 2024 — McMap. All rights reserved.