Skip to content

failglob causes the failure of _variable in generating ${assoc[index]} as a completion #663

@EmilyGraceSeville7cf

Description

@EmilyGraceSeville7cf

Describe the bug

-S compgen option causes _variables function fail for ${array[index (lines 683-684):

        COMPREPLY+=($(compgen -W '$(printf %s\\n "${!'${BASH_REMATCH[2]}'[@]}")' \
            -P "${BASH_REMATCH[1]}${BASH_REMATCH[2]}[" -S ']}' -- "${BASH_REMATCH[3]}"))

Without -S everything works fine.

To reproduce

We can reproduce this behavior interactively inside Bash without _variables function:

  1. declare -A assoc=([aa]=1 [ab]=2)
  2. [[ '${assoc[a' =~ ^(\$\{[#\!]?)([A-Za-z0-9_]*)\[([^]]*)$ ]]
  3. e $(compgen -W '$(printf %s\\n "${!'${BASH_REMATCH[2]}'[@]}")' -P "${BASH_REMATCH[1]}${BASH_REMATCH[2]}[" -S ']}' -- "${BASH_REMATCH[3]}")
  4. See problem

image

Expected behavior

No error expected even with failglob enabled.

Versions (please complete the following information)

  • Operating system name/distribution and version: Linux Mint 20.2 Cinnamon
  • bash version, echo "$BASH_VERSION": 5.1.0(1)-release
  • bash-completion version, (IFS=.; echo "${BASH_COMPLETION_VERSINFO[*]}"): 2 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions