parameter-expansion

Bash associative key presence

With a fixed key, expands word when that element is assigned, even if its value is empty.

Formal Syntax & Structure

bash syntaxbash
${name[key]+word}

Return Value

string

With a fixed key, expands word when that element is assigned, even if its value is empty.

Working Example

Example Snippetbash
declare -A settings=([note]='')printf 'note=%s\nmissing=%s\n' "${settings[note]+present}" "${settings[missing]+present}"
Bash Reference