Shell初探 if和执行语句赋值

file=/port.txt      #里面每个端口号占一行

cat $file | while read port

do

      num=`netstat -ano | grep $port | wc -l`     #统计端口的连接数 , 注意等号两边不能有空格(赋值不能有空格) ,那是反单引号(tab键上面那个有波浪线的键),不是单引号

  if [[ $num -lt 1 ]];then                                #注意if后面有空格,中括号两边也有空格,then要写在分号后面

    echo "error port : $port"                    #若是连接数小于1则是错误端口

  fi

done

原文地址:https://www.cnblogs.com/QTSS/p/7797988.html