[ILUG] shell quiz !
John P . Looney
john at antefacto.com
Fri Feb 16 14:58:12 GMT 2001
Here's a little puzzler. Seeing as "seq" only works in decimals, it's a
little tricky.
Basically, if someone gives me a pair of IP's, like
10.55.2.9
and
10.10.29.2
I want something like a "for $ip in $ips" type loop. I'm thinking at the
moment, something like:
IP_start=10.10.2.9
IP_end=10.10.6.0
for i in `seq 1 4`
do
eval "IP_start_$i=`echo $IP_start | cut -f$i -d. `"
eval "IP_end_$i=`echo $IP_end | cut -f$i -d. `"
done
counter1=$IP_start_1
while [ $counter1 -le $IP_end_1 ] ; do
counter2=$IP_start_2
while [ $counter2 -le $IP_end_2 ] ; do
counter3=$IP_start_3
while [ $counter3 -le $IP_end_3 ] ; do
counter4=$IP_start_4
while [ $counter4 -le $IP_end_4 ] ; do
echo "$counter1.$counter2.$counter3.$counter4"
counter4=$((counter4+1))
done
counter3=$((counter3+1))
done
counter2=$((counter2+1))
done
counter4=$((counter4+1))
done
But, how do I do the "base 256" thing ?
--
When I say 'free', I mean 'free': free from bond, of chain or command:
to go where you will, even to Mordor, Saruman, if you desire. "
-- Gandalf, paraphrasing the choice between Free and Non-free software
More information about the ILUG
mailing list