[Gllug] "ip" command

ccooke ccooke-gllug at gkhs.net
Mon Feb 6 09:46:24 UTC 2006


On Sun, Feb 05, 2006 at 11:55:02PM +0000, Russell Howe wrote:
> On Sat, Feb 04, 2006 at 11:48:35PM +0000, Nix wrote:
> > > netmask_to_cidr() {
> > > 	echo "$1"| (
> > > 		IFS=.
> > > 		read NM1 NM2 NM3 NM4
> > > 
> > > 		NMDEC="$(((NM1 << 24) + (NM2 << 16) + (NM3 << 8) + NM4 ))"
> > > 
> > > 		if [ "$NMDEC" -gt $((0xffffffff)) -o "$NMDEC" -lt 0 ]; then
> > 
> > Pedant: if you have functions and $(()), you certainly have [[ ]] as
> > well.
> 
> Hm, neat. Didn't know about [[ ]]. What I'd really like to do, however,
> is avoid the subshell, but I couldn't see a way to do it nicely.
> 

That's not too hard:

You're using:

echo "$1" | (
	IFS=.
	read NM1 NM2 NM3 NM4
)

Try this:

NM=( ${1://./ } )

and you get an array of the netmask octets.

-- 
echo -ne "\E#8";b=$[X=`tput cols`,Y=`tput lines`,d=1,a=X/2,Y/2];while case $d\
 in 0)((a=a<2?X:a-1));;1)((b=b<2?Y:b-1));;2)((a=a==X?1:a+1));;3)((b=b==Y?1:b+\
1));; esac;do((c=b+a*X));v=${k[c]:- };[ $v. = @. ]&&{((d=d>2?0:d+1));k[c]="";\
}||{(( d=d<1?3:d-1));k[c]=@;};echo -ne "\E[$b;${a}H$v";done # Charles Cooke
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list