#!/bin/bash
# -A declares v to be an associative array
# [key]=vlaue
declare -A v
v=(
["var1"]="variable 01"
["var2"]="variable 02"
["var3"]="variable 03"
["var4"]="variable 01"
)
# ${!v[@]} gives us the keys
# to access the value use ${v[key]}
for k in ${!v[@]}
do
echo "v: [$k] => [${v[$k]}]"
done
# key can have spaces
declare -A vws
vws=(
["var 1"]="variable 01"
["var 2"]="variable 02"
)
echo "vsw: [var 1] => [${vws['var 1']}]"
echo "vsw: [var 2] => [${vws['var 2']}]"
No comments :
Post a Comment