# octects
oct1=`echo $subnet | awk -F . ‘{print $1}’`
oct2=`echo $subnet | awk -F . ‘{print $2}’`
oct3=`echo $subnet | awk -F . ‘{print $3}’`
oct4=`echo $subnet | awk -F . ‘{print $4}’`Later, when reviewing my script, Anonymous Coward offered this little gem:
$ set `echo 10.20.30.40 | tr ‘.’ ‘ ‘`
Ok, that’s a reduction from 12 forks and 8 execs to 3 forks and 2 execs.
but you can do it with zero:
IFS=. set 10.20.30.40
Hrmmm.
$ IFS=. set 10.20.30.40
$ echo $2
$ IFS=.
$ set 10.20.30.40
$ echo $2
$ echo $1
10 20 30 40
Did I miss something or are you running bash?
-danny
It doesn’t work for me either in an interactive bash session. However, it works just fine on Solaris /bin/sh:
#!/bin/sh
IFS=.
set 1.2.3.4
echo “$1 – $2 – $3 – $4″