Why isnt my bash array append working?

This script was working just fine on an AIX box, but now on RH linux box the arrays just dont seem to work. Version on the new RH box is 4.1.2

I declare my array

declare -a gridNames=()

I get information about a grid

gridstats=`snmpwalk -v 2c -c splunk $host gridStatsTable -m $APPLIANCEMIB -OUQs -Ln`

As well as getting the stats from the above, I reuse it to find all the gridNames and then will use the array of gridNames to get stats about their maps.

while read -r process; do
        gridNames=(${gridNames[@]} `grep gridName | awk -F """ '{print $(NF-1)}'`)
done <<< "$gridstats"

The awk part is tested and correctly returns a list of gridnames (just one in this case) but when I echo the array gridNames its empty.

I have also tried using

gridNames+=(`grep gridName | awk -F """ '{print $(NF-1)}'`)

but that doesnt work either


Source: bash

Leave a Reply