Monday, May 6, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 1087  / 3 Years ago, thu, july 29, 2021, 6:25:24

I tryed to enable shell autocompletion uncommenting the following lines in my .bashrc:



# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi


However, this have a side effect. Even though autocomplete seems to work, when I open a new terminal, only a blinking cursor is presented:



enter image description here



I am returned to the usual user@machine:~$ prompt only after pressing Ctrl+C.



The normal behavior is restored if I comment the above lines (but no autocompletion any more).



I can't figure out what the problem is.



--Update 1--



Here's what the code does:



enter image description here



--Update 2--



Here's the output of the suggested commands. Somethings keeps looping and the terminal is flooded by the ouptut.



++++++ : /etc/bash_completion.d
++++++ readonly BASH_COMPLETION_COMPAT_DIR
++++++ _blacklist_glob='@(acroread.sh)'
++++++ shopt -s extglob progcomp
++++++ complete -d pushd
++++++ complete -u write chfn groups slay w sux runuser
++++++ complete -A stopped -P '"%' -S '"' bg
++++++ complete -j -P '"%' -S '"' fg jobs disown
++++++ complete -v readonly unset
++++++ complete -A setopt set
++++++ complete -A shopt shopt
++++++ complete -A helptopic help
++++++ complete -a unalias
++++++ complete -A binding bind
++++++ complete -c command type which
++++++ complete -b builtin
++++++ [[ linux-gnu == *@(solaris|aix)* ]]
++++++ [[ linux-gnu == *@(solaris|aix)* ]]
++++++ [[ linux-gnu == *@(solaris|aix)* ]]
++++++ _backup_glob='@(#*#|*@(~|.@(bak|orig|rej|swp|dpkg*|rpm@(orig|new|save))))'
++++++ complete -F _service service
++++++ _sysvdirs
++++++ sysvdirs=()
++++++ [[ -d /etc/rc.d/init.d ]]
++++++ [[ -d /etc/init.d ]]
++++++ sysvdirs+=(/etc/init.d)
++++++ [[ -f /etc/slackware-version ]]
++++++ for svcdir in '${sysvdirs[@]}'
++++++ for svc in '$svcdir/!($_backup_glob)'
++++++ [[ -x /etc/init.d/acpid ]]
++++++ complete -F _service /etc/init.d/acpid
++++++ for svc in '$svcdir/!($_backup_glob)'
++++++ [[ -x /etc/init.d/anacron ]]
++++++ complete -F _service /etc/init.d/anacron
++++++ for svc in '$svcdir/!($_backup_glob)'
++++++ [[ -x /etc/init.d/apparmor ]]


--Update 3--



Here's the requested output:



ac@ac:~$ grep -r bash_completion /etc/bash_completion.d
/etc/bash_completion.d/bash.bashrc:# if [ -f /usr/share/bash-completion/bash_completion ]; then
/etc/bash_completion.d/bash.bashrc:# . /usr/share/bash-completion/bash_completion
/etc/bash_completion.d/bash.bashrc:# elif [ -f /etc/bash_completion ]; then
/etc/bash_completion.d/bash.bashrc:# . /etc/bash_completion
/etc/bash_completion.d/bash.bashrc.bak:# if [ -f /usr/share/bash-completion/bash_completion ]; then
/etc/bash_completion.d/bash.bashrc.bak:# . /usr/share/bash-completion/bash_completion
/etc/bash_completion.d/bash.bashrc.bak:# elif [ -f /etc/bash_completion ]; then
/etc/bash_completion.d/bash.bashrc.bak:# . /etc/bash_completion
/etc/bash_completion.d/inkscape:# put this file in /etc/bash_completion.d/
/etc/bash_completion.d/desktop-file-validate:# put this file in /etc/bash_completion.d/
/etc/bash_completion.d/bash_completion~:. /usr/share/bash-completion/bash_completion
/etc/bash_completion.d/git-completion.bash:# bash_completion - programmable completion functions for bash 3.2+
/etc/bash_completion.d/libreoffice.sh:# Programmable bash_completion file for the main office applications
/etc/bash_completion.d/bash_completion:# . /usr/share/bash-completion/bash_completion


Indeed the last line shows what you predicted.
But I don't know what to do with that file: should I delete it, or I mistakenly overwrote it?
If so, what was the original content?


More From » command-line

 Answers
0

The fact that the output you get with set -x contains so many plus signs (++++++) means that /usr/share/bash-completion/bash_completion is being re-sourced recursively.



In other words, /usr/share/bash-completion/bash_completion is "calling" himself, resulting in a sort of infinite loop, as you noted.



If I were you, I would check /etc/bash_completion.d looking for references to /usr/share/bash-completion/bash_completion. Specifically, here is what I would do:




  1. ls -l /etc/bash_completion.d (there must be no symlinks to /usr/share/bash-completion/bash_completion);

  2. grep -r bash_completion /etc/bash_completion.d (none of the files in /etc/bash_completion.d should source /usr/share/bash-completion/bash_completion).



Alternatively, you can run these two commands in your shell (without bash completion enabled, of course):



set -x
. /usr/share/bash-completion/bash_completion |& grep -E "^++ (.|source)"


This will print all "imports" and will help us identify the nasty piece of code that is causing the problem.






From the output of grep -r bash_completion /etc/bash_completion.d you can see many matches. Most of them are comments (because they start with #), but there's an interesting line:



/etc/bash_completion.d/bash_completion~:. /usr/share/bash-completion/bash_completion


/etc/bash_completion.d/bash_completion~ is the culprit. This is the file that is causing the recoursive re-source.



/usr/share/bash-completion/bash_completion in fact automatically sources every file in the /etc/bash_completion.d directory. But this directory, in your case, contains the bash_completion~ file, which is sourcing /usr/share/bash-completion/bash_completion again. This results in the sort of loop that you are experiencing.



So go ahead and delete it!



sudo rm /etc/bash_completion.d/bash_completion~


(Or maybe read it if you believe it contains something useful.)



I cannot tell you why that file was in that directory. What I can tell you is that the suffix ~ means that this is a backup file. Many text editors (including Gedit) create backup copies upon saving. Probably it was left there by mistake while you were making changes.


[#23792] Thursday, July 29, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deringach

Total Points: 412
Total Questions: 107
Total Answers: 101

Location: Palestine
Member since Tue, Jul 20, 2021
3 Years ago
deringach questions
Sat, Oct 30, 21, 17:38, 3 Years ago
Fri, Oct 21, 22, 16:34, 2 Years ago
Tue, Feb 15, 22, 22:33, 2 Years ago
Tue, Feb 7, 23, 03:57, 1 Year ago
;