Bug 385271

Summary: /etc/bash_completion silently crashes, stopping execution of sourced .bashrc and .bash_profile scripts
Product: [Fedora] Fedora Reporter: Need Real Name <bugzilla>
Component: bash-completionAssignee: Ville Skyttä <ville.skytta>
Status: CLOSED WORKSFORME QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: low    
Version: 8CC: axel.thimm, sheltren
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2007-11-19 18:20:14 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Need Real Name 2007-11-15 18:55:49 UTC
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 19:18:24 UTC
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-18 02:30:14 UTC
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 11:00:27 UTC
(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 11:36:47 UTC
(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 17:43:21 UTC
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 18:20:14 UTC
Thanks for the info.  Not sure why ATrpms ships a bash-completion package for
Fedora in the first place though.