Tuesday, April 5, 2016

Printing key-value pairs from Bash Associative array

#!/bin/bash 

 ## Printing key-value pairs from a Bash associative array 
unset myarr && declare -A myarr 
let myarr["eightytwo"]+=8
let myarr["eightytwo"]+=74
myarr["thirteen"]+=1
myarr["thirteen"]+=3
let myarr["fiftythree"]+=48
let myarr["fiftythree"]+=5
for a in "${!myarr[@]}"; do echo "${a}: ${myarr["$a"]}"; done

No comments:

Post a Comment