#!/opt/local/bin/bash
THRESHOLD=0
SUBJECT_HOURLY="'Hourly'"
SUBJECT_DAILY="'Daily'"
DAILY=`df -h | grep -i "/Volumes/Daily" | awk '{print $5}' | sed "s/%//"`
HOURLY=`df -h | grep -i "/Volumes/Hourly" | awk '{print $5}' | sed "s/%//"`
declare -A MyArray
MyArray=( [$HOURLY]=$SUBJECT_HOURLY [$DAILY]=$SUBJECT_DAILY )
for KEY in "${!MyArray[@]}"; do
echo "$KEY" "${MyArray[$KEY]}"
done
------------------
Expected result:
2 'Hourly'
2 'Daily'
Wrong result I always get is:
2 'Daily'
Why is my code not printing out the 1st key/value? It seems to skip the 1st key/value every time. Even if I swap the key pairs positions,
it just prints the 2nd key/value.
THRESHOLD=0
SUBJECT_HOURLY="'Hourly'"
SUBJECT_DAILY="'Daily'"
DAILY=`df -h | grep -i "/Volumes/Daily" | awk '{print $5}' | sed "s/%//"`
HOURLY=`df -h | grep -i "/Volumes/Hourly" | awk '{print $5}' | sed "s/%//"`
declare -A MyArray
MyArray=( [$HOURLY]=$SUBJECT_HOURLY [$DAILY]=$SUBJECT_DAILY )
for KEY in "${!MyArray[@]}"; do
echo "$KEY" "${MyArray[$KEY]}"
done
------------------
Expected result:
2 'Hourly'
2 'Daily'
Wrong result I always get is:
2 'Daily'
Why is my code not printing out the 1st key/value? It seems to skip the 1st key/value every time. Even if I swap the key pairs positions,
it just prints the 2nd key/value.