[Wylug-help] Bash Completion on Centos

Smylers Smylers at stripey.com
Tue Nov 24 15:36:46 UTC 2009


I wrote:

> Hi.  Sourcing /etc/bash_completion is failing for me:

I've narrowed this down a bit.  Red Hat's bash-completion package
includes /etc/profile.d/bash_completion.sh, which sources
/etc/bash_completion -- so if bash-completion is installed, all users
get its behaviour by default.

My .bashrc also sources /etc/bash_completion, not expecting the
system-wide behaviour (which Ubuntu doesn't have).  And it's sourcing
this file a second time which is making it fail.

But ... that doesn't explain _why_ it's failing.  The relevant lines:

  {               
    # These declarations must go within braces in order to be able to silence
    # readonly variable errors.
    BASH_COMPLETION="${BASH_COMPLETION:-/etc/bash_completion}"
    BASH_COMPLETION_DIR="${BASH_COMPLETION_DIR:=/etc/bash_completion.d}"
  } 2>/dev/null || :
  readonly BASH_COMPLETION BASH_COMPLETION_DIR

And indeed because the first time through that made BASH_COMPLETION
read-only, it fails the second time when trying to set it.

Except the comments and above construction look like the author
specifically anticipated this and tried to protect against it.  So it
should still work.

The redirection to /dev/null does indeed silence the error message, but
it seems the error itself is sufficiently severe that rather than just
being a command which returns an error code (which would itself be
squashed by the || : alternative) it causes the surrounding script to
abort.

Anybody got any ideas why?

Smylers



More information about the Wylug-help mailing list