less maskdigits.sh
#!/bin/sh
#maskdigits.sh mask a=$(echo "$1" | awk -F "." '{print $1" "$2" "$3" "$4}') for num in $a; do while (($num!=0));do echo -n $(($num%2)) >> /tmp/$$.num; num=$(($num/2)); done done echo $(grep -o "1" /tmp/$$.num | wc -l) rm /tmp/$$.num例如:maskdigits.sh 255.255.0.192
18