Skip to content

Instantly share code, notes, and snippets.

@amekusa
Last active April 21, 2023 07:51
Show Gist options
  • Select an option

  • Save amekusa/0a947cf2e02f64945f3f70ea30335c29 to your computer and use it in GitHub Desktop.

Select an option

Save amekusa/0a947cf2e02f64945f3f70ea30335c29 to your computer and use it in GitHub Desktop.
Iterate over key-value array in bash
arr=(
name="John Doe"
age=32
job="Software Engineer"
)
for each in "${arr[@]}"; do
key="${each%%=*}"
val="${each:$((${#key}+1))}"
echo "$key: $val"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment