Skip to main content
Fixed formatting
Source Link
terdon
  • 252.2k
  • 69
  • 480
  • 718

I have a bash script that is running an SNMPGET of two values. I want to take the results and put them in an array.

Here is the code:

OUTPUT=`snmpget -v2c -c public -Oqv 192.168.0.33'
' sysName'
' SysLocation' echo $OUTPUT ARRAY=($OUTPUT) echo ${ARRAY[0]}

OUTPUT=`snmpget -v2c -c public -Oqv 192.168.0.33' \
' sysName'\
' SysLocation'
echo  $OUTPUT
ARRAY=($OUTPUT)
echo ${ARRAY[0]}

echo $OUTPUTecho $OUTPUT returns "Private Network" "Server 4 ""Private Network" "Server 4 ".

When I put it in an array and do:

echo ${ARRAY[0]}

echo ${ARRAY[0]} it Returns "Private"Private

How do I alter my script so that the qualifier for the array, is not the space in between words so for echo ${ARRAY[0]}${ARRAY[0]} it Returns "Private Network""Private Network"?

I have a bash script that is running an SNMPGET of two values. I want to take the results and put them in an array.

Here is the code:

OUTPUT=`snmpget -v2c -c public -Oqv 192.168.0.33'
' sysName'
' SysLocation' echo $OUTPUT ARRAY=($OUTPUT) echo ${ARRAY[0]}

echo $OUTPUT returns "Private Network" "Server 4 "

When I put it in an array and do:

echo ${ARRAY[0]} it Returns "Private

How do I alter my script so that the qualifier for the array, is not the space in between words so for echo ${ARRAY[0]} it Returns "Private Network"?

I have a bash script that is running an SNMPGET of two values. I want to take the results and put them in an array.

Here is the code:

OUTPUT=`snmpget -v2c -c public -Oqv 192.168.0.33' \
' sysName'\
' SysLocation'
echo  $OUTPUT
ARRAY=($OUTPUT)
echo ${ARRAY[0]}

echo $OUTPUT returns "Private Network" "Server 4 ".

When I put it in an array and do:

echo ${ARRAY[0]}

it Returns "Private

How do I alter my script so that the qualifier for the array, is not the space in between words so for echo ${ARRAY[0]} it Returns "Private Network"?

Source Link

Setting Qualifiers for Bash Array

I have a bash script that is running an SNMPGET of two values. I want to take the results and put them in an array.

Here is the code:

OUTPUT=`snmpget -v2c -c public -Oqv 192.168.0.33'
' sysName'
' SysLocation' echo $OUTPUT ARRAY=($OUTPUT) echo ${ARRAY[0]}

echo $OUTPUT returns "Private Network" "Server 4 "

When I put it in an array and do:

echo ${ARRAY[0]} it Returns "Private

How do I alter my script so that the qualifier for the array, is not the space in between words so for echo ${ARRAY[0]} it Returns "Private Network"?