Skip to content

[Bash] Don't nest ${} parameter expansion on { #216

@zufuliu

Description

@zufuliu

https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion

When braces are used, the matching ending brace is the first ‘}’ not escaped by a backslash or within a quoted string, and not within an embedded arithmetic expansion, command substitution, or parameter expansion.

following code (from __parse_options() inside msys2's usr\share\bash-completion\bash_completion script) is messed by incorrect nesting:

# Expand --[no]foo to --foo and --nofoo etc
if [[ $option =~ (\[((no|dont)-?)\]). ]]; then
    option2=${option/"${BASH_REMATCH[1]}"/}
    option2=${option2%%[<{().[]*}
    printf '%s\n' "${option2/=*/=}"
    option=${option/"${BASH_REMATCH[1]}"/"${BASH_REMATCH[2]}"}
fi

option=${option%%[<{().[]*}
printf '%s\n' "${option/=*/=}"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bashCaused by the bash lexer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions