Bug 385271 - /etc/bash_completion silently crashes, stopping execution of sourced .bashrc and .bash_profile scripts
/etc/bash_completion silently crashes, stopping execution of sourced .bashrc...
Status: CLOSED WORKSFORME
Product: Fedora
Classification: Fedora
Component: bash-completion (Show other bugs)
8
All Linux
low Severity high
: ---
: ---
Assigned To: Ville Skyttä
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2007-11-15 13:55 EST by Need Real Name
Modified: 2007-11-30 17:12 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2007-11-19 13:20:14 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Need Real Name 2007-11-15 13:55:49 EST
Description of problem:
When I source my .bash_profile script (based on the Fedora default), it sources
the following scripts in sequence:

~/.bash_profile -> ~/.bashrc -> /etc/bashrc -> /etc/profile.d/bash_completion.sh
-> /etc/bash_completion.

However, the scripts are never fully executed, because the bash_completion
script silently crashes on *each* of the following two lines:
   BASH_COMPLETION="${BASH_COMPLETION:-/etc/bash_completion}"
   BASH_COMPLETION_DIR="${BASH_COMPLETION_DIR:=/etc/bash_completion.d}"

The crashes are silent because stdout and stderr are redirected to /dev/null.
The comment says that the purpose is to "silence readonly variable errors". The
reality is that the errors abort the script even when silenced.

Note this problem doesn't seem to occur when .bashrc is sourced as part of a
login or new bash shell process.

However, people are used to being able to (re) source their .bash_profile and
.bashrc files and this error causes them all to abort!
Comment 1 Ville Skyttä 2007-11-15 14:18:24 EST
I can't reproduce.  When I source my (also based on Fedora defaults)
~/.bash_profile manually, /etc/bash_completion is never even read because the
first check in /etc/profile.d/bash_completion.sh notices that it has already
been sourced.

How have you determined that /etc/bash_completion is sourced when you (re)source
~/.bash_profile and that those two lines are causing problems?
Comment 2 Need Real Name 2007-11-17 21:30:14 EST
Yes... by trial-and-error (using echo statements), I followed the chain as
above. Everything gets sourced down the chain.
Each of the lines noted above caused the crash -- and everything loaded smoothly
when I commented them out. I (obviously) get the same problem when I just source
/etc/bash_completion directly or when I run the lines directly from the bash prompt.

The errors I get are:
    bash: BASH_COMPLETION: readonly variable
    bash: BASH_COMPLETION_DIR: readonly variable

I don't understand what you mean by "the first check in
/etc/profile.d/bash_completion.sh notices that it has already
been sourced.

The first check is a return if $BASH_VERSION is not set (which it is), so
nothing happens. The second check is whether $BASH_VERSION > 2.04, which it is
so it proceeds to the third check which checks whether /etc/bash_completion is
readable, which it is. So, the file /etc/bash_completion is then sourced.

Comment 3 Ville Skyttä 2007-11-18 06:00:27 EST
(In reply to comment #2)
> Yes... by trial-and-error (using echo statements), I followed the chain as
> above. Everything gets sourced down the chain.

I used the same method, and it does *not* get sourced for me.  Additionally,
directly sourcing /etc/bash_completion multiple times in a row causes no
"crashes" either.

> I don't understand what you mean by "the first check in
> /etc/profile.d/bash_completion.sh notices that it has already
> been sourced.
> 
> The first check is a return if $BASH_VERSION is not set (which it is), so
> nothing happens.

The first check additionally checks if $BASH_COMPLETION is nonempty:

# Check for bash (and that we haven't already been sourced).
[ -z "$BASH_VERSION" -o -n "$BASH_COMPLETION" ] && return
Comment 4 Ville Skyttä 2007-11-18 06:36:47 EST
(In reply to comment #3)

> directly sourcing /etc/bash_completion multiple times in a row causes no
> "crashes" either.

However I do see that some debug "echo foo >> /tmp/foo" do stop printing when
repeatedly sourcing bash_completion in the section you mentioned.  Changes
further down bash_completion do take effect despite of this.
Comment 5 Need Real Name 2007-11-19 12:43:21 EST
OK - I see what's wrong. My version of bash_completion.sh doesn't have the
second part of the test (-o -n "$BASH_COMPLETION").

When I looked closely, I noticed that yum had pulled in the version of
bash-completion from the atrpms repo. I will 'cc' Axel Thimm on this to allow
him to fix his version.

Axel: you may want to update your version by making sure it has the line:
# Check for bash (and that we haven't already been sourced).
[ -z "$BASH_VERSION" -o -n "$BASH_COMPLETION" ] && return

Sorry for the confusion - I wish there were a way to more explicitly know when
one of the other repos overrides a standard fedora rpm :)


Comment 6 Ville Skyttä 2007-11-19 13:20:14 EST
Thanks for the info.  Not sure why ATrpms ships a bash-completion package for
Fedora in the first place though.

Note You need to log in before you can comment on or make changes to this bug.