/etc/profile.d/bash_completion.sh only sources /usr/share/bash-completion/bash_completion if it hasn't been already. note the check on -z "$BASH_COMPLETION_COMPAT_DIR", which the giant bash_completion script defines with
So I guess BASH_COMPLETION_COMPAT_DIR is the canonical way to check if it's already loaded, since the variable gets marked readonly. (That prevents even unset from working on it.)
This doesn't help if profile.d goes first, and then bash.bashrc or the user's ~/.bashrc sources completions without checking, though.
The commented-out lines in the default /etc/bash.bashrc should have the same check added, if they haven't. My /etc/bash.bashrc.dpkg-old from 2013 still shows it with the crusty old:
# enable bash completion in interactive shells
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
# . /etc/bash_completion
#fi
/etc/profile.d is a silly place to have this, though. How and whether programmable completion is enabled by default is a topic for another bug, but I don't think there's any way to justify having it for login shells but not for non-login shells. xterm, gnome-terminal, etc. all normally start non-login shells.
/etc/profile. d/bash_ completion. sh only sources /usr/share/ bash-completion /bash_completio n if it hasn't been already. note the check on -z "$BASH_ COMPLETION_ COMPAT_ DIR", which the giant bash_completion script defines with
: ${BASH_ COMPLETION_ COMPAT_ DIR:=/etc/ bash_completion .d} _COMPAT_ DIR
readonly BASH_COMPLETION
So I guess BASH_COMPLETION _COMPAT_ DIR is the canonical way to check if it's already loaded, since the variable gets marked readonly. (That prevents even unset from working on it.)
This doesn't help if profile.d goes first, and then bash.bashrc or the user's ~/.bashrc sources completions without checking, though.
The commented-out lines in the default /etc/bash.bashrc should have the same check added, if they haven't. My /etc/bash. bashrc. dpkg-old from 2013 still shows it with the crusty old: completion ] && ! shopt -oq posix; then completion
# enable bash completion in interactive shells
#if [ -f /etc/bash_
# . /etc/bash_
#fi
/etc/profile.d is a silly place to have this, though. How and whether programmable completion is enabled by default is a topic for another bug, but I don't think there's any way to justify having it for login shells but not for non-login shells. xterm, gnome-terminal, etc. all normally start non-login shells.