Bash auto-complete of environment variables
Recently I reinstalled ubuntu and I noticed a small but annoying problem with auto complete.
Say I have a $SOME_DIR variable. If I type $SOME and hit tab I get Code:
cd \$SOME_DIR Second, if I use an env variable with any other command, e.g. ls, the auto complete isn't triggered at all.. I haven't come across this problem before and would appreciate any pointers. Thanks in advance, armandino |
first try looking into each text file at /etc/bash_completion.d
then turn on hidden files and look at /home/yourname/bash"stuff" I have 6 files there if none of that works and you know the exact phrase, since you only say it could be $SOME_DIR....whatever it is ....try grep but that may take a long time or find eg find /etc -type f -print |xargs grep -n "$SOME_DIR" try a "zzz" first to see it should produce nil result...meaning it aint there. |
Hi,
Thanks for the tips. I think I may not have described the problem clearly. The problem is that bash escapes the dollar sign of an environment variable when I use the cd command. $SOME_DIR was just an example. It could be any variable. To explain again, say the environment variable points to some directory Quote:
Quote:
Quote:
|
please report your post to a moderator and ask them to move it to a programming forum cos I can not help. Sorry to have mislead you.
|
Hey, no worries. I appreciate your help.
Mods, if you feel there's a more appropriate forum for this question, please move it there :) |
I haven't found a proper solution to this, but there's a workaround. The escaping of environment variables can be disabled by pressing Esc followed by tab.
For example, Code:
# cd $SO + [Esc] + [Tab] |
Solution
Quick Answer
Code:
shopt -s cdable_vars Short Answer Put "shopt -s cdable_vars" in a start-up script. -- This will give a permanent solution. I haven't done this yet, not sure which one to use. Context I am still running SimplyMEPIS 3.3.2 -- based on Debian Etch, back when it was "Testing", not "Stable" as it is now. All of this is based on what I found on my own system. Notes
Key Clue (From less -SN /etc/bash_completion) Code:
3000 if shopt -q cdable_vars; then Code:
$ help complete
Code:
5 # Copyright (C) Ian Macdonald <ian@caliban.org> 1. OMG, MEPIS has a "service" (ser<TAB>) cmd., & also "invoke-rc.d" (inv<TAB>). -- Check out their man pages. 2. Code:
$ umount <TAB><TAB> |
Hi!
Thanks for posting the solution. It worked perfectly well. I think the complete command could do with more documentation. It has no man page or help output other than a two-line usage information. Re: Quote:
Also, from the man page: Code:
-a All of the file systems described in /etc/mtab are unmounted. |
AFAIK, only external commands (config files etc.) have man pages. Because it is a bash built-in, complete is documented inside the (incredibly long) bash man page. That is why I gave you the following search phrases:
Quote:
Code:
help complete |
Solution
To the original poster's issue, his problem is likely because dash rather than bash is configured as the default shell.
Just run 'sudo dpkg-reconfigure dash' and when prompted do not set dash as default. |
SOLUTION for Ubuntu 12.04
This bug (tab complete not working on environment variables) is present in Ubuntu 12.04. It is a bug in bash-4.2. Applying patch bash4.2-029 solves the problem. See https://bugs.launchpad.net/ubuntu/+s...27/comments/14
|
It is also happening in Linux Mint 14 nadia. I used variables a lot and this is
starting to put me off! What is the best way to solve this ? |
All times are GMT -5. The time now is 07:34 PM. |