Key-Value Pair

noun

say it: “KEE VAL-yoo PAIR” /ˈki ˈvæljuː ˈpɛr/

One entry in a list that is looked up by name: the name, called the key, and what is stored under it, called the value.

What is a key-value pair in a bash associative array?

A key-value pair is one slot of an associative array: a name, the key, and what's stored under it, the value. In best[chill]="Window Down", chill is the key and Window Down the value. Each key appears once; storing under it again replaces the value.

declare -A best
best[chill]="Window Down"
best[upbeat]="Paper Lanterns"
echo "${#best[@]} pairs"   # 2 pairs
for mood in "${!best[@]}"; do echo "$mood: ${best[$mood]}"; done
# chill: Window Down
# upbeat: Paper Lanterns

In a sentence

  • “chill and Window Down make one key-value pair in the best array.”
  • “The spending total has a key-value pair for food, bus and fun.”

Level: Journeyman · More Unix terms at this level

Updated

In other subjects