A little problem with bash && ping

Hello guys .
(before starting excuse me for my poor English .I'm trying to learn it ;) )
I have a little problem when a want to ping some Ip addresses .
So this is my simple code :
Code:
ping(){
ip=(4.2.2.2 4.2.2.4 50.50.50.1 )
 
for ((i=0 ; i< 3 ; i++));do

if [ "$(ping -c 1 ${ip[$i]} | grep "icmp_seq" )" != ""  ];then
   echo "[$i]${ip[$i]}"
fi

done
}

ping

My problem is here :

After starting script the bash goes to making a lot of threads (like as c programs !!)
and all CPUs engaged. And finally the machine is not responsible and i force to reboot by key.
The kernel shows the error : ... uid (1001) out of swap space !

So is it a bug ? and how can is solve it ?

oss : FreeBSD BLOGGER1 6.4-STABLE && FreeBSD BLOGGER2 8.0-STABLE

thanks
 
Try that one:
Code:
#! /bin/sh

for IP in 4.2.2.2 4.2.2.4 50.50.50.1
do
  [ "$( ping -c 1 ${IP} | grep 'icmp_seq' )" = "" ] || {
    echo "${IP}"
    }
done

... and use #! /bin/sh for scripts.
 
Back
Top