Package: bash
Version: 4.4-4
Followup-For: Bug #713051
This bug report is correct, however, the situation is a little more
complicated.
/etc/profile.d/bash_completion.sh already contains code that checks whether
bash_completion has already run. Hence, there should be no need to uncomment
the code in /etc/bash.bashrc.
However, /etc/profile.d/bash_completion.sh does not load bash_completion if
the current bash is non-interactive. Thus, it depends how your login shell
is set up whether bash_completion is loaded at this stage or not: in a
console login it is loaded, whereas at least on my systemd/GNOME
combination, it is not (it was previously loaded when upstart was in charge
rather than systemd).
It would be nice to simplify the setup. Fortunately, it only involves two
packages: bash supplies /etc/bash.bashrc and /etc/skel/.bashrc, and
bash-completion supplies /etc/profile.d/bash_completion.sh.
This file /etc/profile.d/bash_completion.sh does everything that is
required: it checks that the bash running is new enough, that it is being
run interactively, and that bash_completion has not already been run.
Therefore, it seems to me the logical thing to do is always to call this
file.
Hence, the simplest fix seems to me to replace the code in /etc/bash.bashrc
and in /etc/skel/.bashrc with something like the following (I give the
/etc/skel version, where the code is uncommented, and have added a phrase to
the comment to note that it may not run from /etc/profile):
# 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 in an interactive shell).
if [ -f /etc/profile.d/bash_completion.sh ]; then
. /etc/profile.d/bash-completion.sh
fi
This has another advantage: it also checks for user-overridden
bash_completion in XDG_CONFIG_HOME.
As a consequence, the script should arguably be moved to
/usr/share/bash-completion and suitably renamed, but that’s a matter for the
bash-completion package.
There is another question which is a matter for the bash-completion package:
since bash-completion is only useful in interactive shells, why not remove
the /etc/profile script? The current default is to have the code commented
out in /etc/bash.bashrc, which is fine, because, as I observed above, the
default systemd/GNOME combination won’t run it anyway, and to have
bash_completion loaded by default in .bashrc, which again is fine, because
it’s needed there, and also desirable.
If this simplification is not adopted, then the comment above should be
expanded to mention /etc/profile.d/bash_completion, as otherwise users
administering their own machines may be confused that, for example in a
console login, bash-completion is active even if disabled in both ~/.bashrc
and /etc/bash.bashrc.
-- System Information:
Debian Release: stretch/sid
APT prefers xenial-updates
APT policy: (500, 'xenial-updates'), (500, 'xenial-security'), (500,
'xenial'), (100, 'xenial-backports')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 4.4.0-67-generic (SMP w/4 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
Versions of packages bash depends on:
ii base-files 9.4ubuntu4.4
ii dash 0.5.8-2.1ubuntu2
ii debianutils 4.7
ii libc6 2.23-0ubuntu5
ii libtinfo5 6.0+20160213-1ubuntu1
Versions of packages bash recommends:
ii bash-completion 1:2.1-4.2ubuntu1.1
Versions of packages bash suggests:
ii bash-doc 4.3-14ubuntu1.1
-- no debconf information