Hi,
I have one array created and some values are there in ksh. I want to append some other values to it based on some condition in if statement.
#!/bin/ksh
echo "---------------------------------------------------"
set -A ipaddr_arr $(egrep -v '^#|^::|^$' /etc/hosts |awk '{print $1}' | uniq) #hosts ips
set +A ipaddr_arr $(egrep -v '^#|^::|^$' /etc/hosts |awk '{print $1}')
if [ "$os" = "solaris" ]
then
set +A ipaddr_arr $(egrep -v '^#|^::|^$' /etc/hosts |awk '{print $1}')
else
#some other statement
fi
COUNT=0
for str in ${ipaddr_arr
[*]}
do
echo "$str"
COUNT=$((COUNT+1))
done
However after the if condition is executed as true, the array does not contain previous values. The statement within if overwrites the array values, without appending the values to it. As in ksh, +A is for appending values to array. However here it is not behaving properly.
I tried with only giving this in if block, still it gives error in ksh-
+A ipaddr_arr $(egrep -v '^#|^::|^$' /etc/hosts |awk '{print $1}')
Anyone have any clues..
thanks in advance for your replies.