Simple bash script to generate subnet from ip and netmask which i got after some googling.It as below
#!/bin/bash
sub_net()
{
A=$1
B=$2
OFS=$IFS
IFS="."
set ${A:-0.0.0.0}
A1=${1:-0}
A2=${2:-0}
A3=${3:-0}
A4=${4:-0}
IFS="."
set ${B:-0.0.0.0}
B1=${1:-0}
B2=${2:-0}
B3=${3:-0}
B4=${4:-0}
IFS=$OFS
C4=$(( B4 & A4 ))
C3=$(( B3 & A3 ))
C2=$(( B2 & A2 ))
C1=$(( B1 & A1 ))
echo ${C1}.${C2}.${C3}.${C4}
}
sub_net 181.172.0.111 255.255.255.0
i know the IFS usage it's for field separator but at around line:8 the codeset ${A:-0.0.0.0} written so what is use of it. For debugging i just comment that line but got following error
./script.bash: line 33: 255.255.255.0: syntax error: invalid arithmetic operator (error token is ".255.255.0")
Can anyone explain usage of it?