bash completions in /usr/share/bash-completion generate unbound variable errors

Bug #1813090 reported by James Lin
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
bash (Ubuntu)
New
Undecided
Unassigned
bash-completion (Ubuntu)
New
Undecided
Unassigned

Bug Description

After upgrading from Ubuntu 18.04 LTS to 18.04.1 LTS, I get errors whenever I attempt to tab-complete anything from an interactive bash prompt.

Tab-completing nothing gives me:

    -bash: _xspecs[$cmd]: unbound variable

Tab-completing an existing filename gives me:

    -bash: !ref: unbound variable

I've partially narrowed down the cause to me putting `set -o nounset` in my `.bashrc` file, and something in `/usr/share/bash-completion` is triggering these unbound variable errors. (That is, the errors go away if I remove `set -o nounset` or if I make `/usr/share/bash-completion/bash_completion` exit immediately.)

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better. It seems that your bug report is not filed about a specific source package though, rather it is just filed against Ubuntu in general. It is important that bug reports be filed about source packages so that people interested in the package can find the bugs about it. You can find some hints about determining what package your bug might be about at https://wiki.ubuntu.com/Bugs/FindRightPackage. You might also ask for help in the #ubuntu-bugs irc channel on Freenode.

To change the source package that this bug is filed about visit https://bugs.launchpad.net/ubuntu/+bug/1813090/+editstatus and add the package name in the text box next to the word Package.

[This is an automated message. I apologize if it reached you inappropriately; please just reply to this message indicating so.]

tags: added: bot-comment
affects: ubuntu → bash (Ubuntu)
Revision history for this message
Will Palmer (wmpalmer) wrote :

I've been dealing with this issue for years and finally tracked it down a few minutes ago.
This is caused by the line:

    declare -A _xspecs

around line 1909 of /usr/share/bash-completion/bash_completion

this line *should* read:

    declare -Ag _xspecs

to ensure the _xspecs variable remains in the global scope, regardless of where bash_completion is sourced from.

This has been fixed in the upstream repository for over a year:

    https://github.com/wpalmer/bash-completion/commit/a47bd375bb0f95dc6d388d4097c420bddb72ae33

This also causes errors in which _xspecs, having not been seen to be previously-declared, is treated as a non-associative array, resulting in errors when strings are erroneously treated as arithmetic operations to return an integer (ie: 'invalid arithmetic operator (error token is ".sh")' when trying to complete a command with .sh in the name)

This issue has already been fixed, Ubuntu needs to either sync with upstream, or to apply the patch found at the above link.

In the meantime, the attached patch can be used as a quick workaround

Revision history for this message
Will Palmer (wmpalmer) wrote :

re-adding attachment due to copy&paste error

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "add -g to declare of _xspecs to ensure it stays in the global scope" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.