bashassociative-array

Downside of NOT using quotes for keys of associative array?


Every example I have found tends to go aa["key"]="value" and even with constants, e.g.:

declare -rA aa=( ["lit1"]="value1" ["lit2"]="value2" )

What is the purpose of this, i.e. does it guard against something I am not foreseeing with literals? The purpose is obvious to me when something is about to be expanded within the quotes, but with constants the code then starts to look less, not more readable.

I checked the two best resources I can think of, the reference and Greg's wiki. It's not explicitly covered anywhere, the former conflates it with regular arrays where it was a non-issue.


Solution

  • Downside of NOT using quotes for keys of associative array?

    No downside.

    What is the purpose of this,

    The purpose is to visually represent what is a string and what is a command, and to differentiate between associative and non-associative array. It's cosmetics.

    does it guard against something I am not foreseeing with literals?

    No.