shell位运算ip和掩码相与
时间:2009-04-02 来源:sss0213
- #!/binsh
- ip="192.168.12.23"
- echo "ip is $ip"
- mask="255.255.0.0"
- echo "mask is $mask"
- aa()
- {
- local cc=""
- for i in 1 2 3 4
- do
- let "aa = $(echo $1 | cut -d '.' -f $i) & $(echo $2 | cut -d '.' -f $i)"
- if [ -n "$cc" ]
- then
- cc="$cc.$aa"
- else
- cc="$aa"
- fi
- done
- echo "$cc"
- }
- dd=$(aa $ip $mask)
- echo "dd $dd"
相关阅读 更多 +