# A little problem with bash && ping



## t4z3v4r3d (Mar 17, 2010)

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 :

```
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


----------



## vermaden (Mar 17, 2010)

Try that one:

```
#! /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.


----------



## fat64 (Mar 17, 2010)

Your ping() function is recursive.  Change its name to something else e.g. xping().

Google found this example.


----------



## t4z3v4r3d (Mar 17, 2010)

Thanks  solved


----------

