You forgot to place your values inside ():
declare -a RESULT=($(/usr/bin/snmpwalk -v 2c -c public 10.10.0.20 .1.3.6.1.4.1.6876.57.101.2 | grep vmdk | awk {' print $4,$5 '} | sed 's/ /_size:/g' | sed 's/\"//g'))
To prevent possible pathname expansion
it's recommended to use read
instead:
declare -a RESULT
IFS=$' \t\n' read -rd '' -a RESULT < <(/usr/bin/snmpwalk -v 2c -c public 10.10.0.20 .1.3.6.1.4.1.6876.57.101.2 | grep vmdk | awk {' print $4,$5 '} | sed 's/ /_size:/g' | sed 's/\"//g')
If you're going to read line by line use readarray
and process substitution
:
readarray -t RESULT < <(/usr/bin/snmpwalk -v 2c -c public 10.10.0.20 .1.3.6.1.4.1.6876.57.101.2 | grep vmdk | awk {' print $4,$5 '} | sed 's/ /_size:/g' | sed 's/\"//g')
Or here strings
and command substitution
:
readarray -t RESULT <<< "$(/usr/bin/snmpwalk -v 2c -c public 10.10.0.20 .1.3.6.1.4.1.6876.57.101.2 | grep vmdk | awk {' print $4,$5 '} | sed 's/ /_size:/g' | sed 's/\"//g')"
You could also use while read
loop:
declare RESULT=()
while read -r LINE; do
RESULT[${#RESULT[@]}]=$LINE
done < <(/usr/bin/snmpwalk -v 2c -c public 10.10.0.20 .1.3.6.1.4.1.6876.57.101.2 | grep vmdk | awk {' print $4,$5 '} | sed 's/ /_size:/g' | sed 's/\"//g')
A simpler approach to your command also is:
/usr/bin/snmpwalk -v 2c -c public 10.10.0.20 .1.3.6.1.4.1.6876.57.101.2 | awk -F '"' '/vmdk/{ t = $2; sub(/ /, "_size:", t); print t; }'