parameter-expansion

Bash @K transformation

Formats an array as a quoted key/value representation suitable for inspection. With the quoted @K expansion in this example, the complete representation occupies one argument. Do not evaluate its output from untrusted data; associative iteration order is not a contract. Bash 5.x feature, tested on 5.2. Run in a fresh private directory with HOME set to that directory and LC_ALL=C. Expected output (one item per line): arguments=1; key and value present.

Formal Syntax & Structure

bash syntaxbash
${parameter@K}

Parameters & Attributes

NameTypeDescription
parametershell parameterTrusted parameter to transform.

Return Value

expanded words

Expansion yields data rather than a separate command status.

Working Example

Example Snippetbash
declare -A data=([one]='two words')set -- "${data[@]@K}"printf 'arguments=%s\n' "$#"[[ $1 == *one* && $1 == *'two words'* ]] || exit 1printf 'key and value present\n'
Bash Reference