Bug 22022 - broken code in /etc/bash_completion: can't be sourced a second time
Summary: broken code in /etc/bash_completion: can't be sourced a second time
Status: CLOSED FIXED
Alias: None
Product: Branch 5.0
Classification: Distributions
Component: bash-completion (show other bugs)
Version: unspecified
Hardware: all Linux
: P3 minor
Assignee: murygin@altlinux.org
QA Contact: qa-5.0@altlinux.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-22 06:03 MSD by Ivan Zakharyaschev
Modified: 2017-07-24 12:14 MSK (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Zakharyaschev 2009-10-22 06:03:36 MSD
bash-completion-20060301-alt06
bash-3.2.39-alt2

At the beginning of /etc/bash_completion, there is a code piece which is broken (doesn't meet its purpose):

# Alter the following to reflect the location of this file.
#
{
  # 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

because if one sources it a second time, it actually bails out at this place rather than silently ignoring the errors from the reassignments of the "readonlies" as intended.

Illustration:

$ readonly x=1; { x="${x:-2}"; } 2> /dev/null || :; echo PASSED
$ 

If it worked as it was intended by the author, PASSED would be printed.

Probably, the solution would be to use the form "${x:=2}" instead of the present assignments:

$ readonly x=1; { : ${x:=2}; } 2> /dev/null || :; echo "PASSED with x holding '$x'."
bash: x: readonly variable
PASSED with x holding '1'.
$ 

Demonstration: Tracing what actually happens when sourcing the current variant for a second time:

[ivan@dell ~]$ set -x; . /etc/bash_completion
+ . /etc/bash_completion
++ '[' -n '' ']'
++ set +v
++ echo -ne '\033]0;ivan@dell: /home/ivan\007'
[ivan@dell ~]$ 


This error makes it inconvenient to test a new ~/.bash_profile like this:

$ . ~/.bash_profile

because this way it stops processing at /etc/bash_completion.
Comment 1 ildar 2017-07-24 12:14:23 MSK
Похоже, починилось.