Last active
April 21, 2023 07:51
-
-
Save amekusa/0a947cf2e02f64945f3f70ea30335c29 to your computer and use it in GitHub Desktop.
Iterate over key-value array in bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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