Linux脚本(二)

1.for循环以及加法的使用

portStr=`lsof -i:56801 | head -2`
count=0
for str in `lsof -i:56801 | head -2`
do
 ((count=count+1))
 echo "Count: $count"
 if [ $count == 11 ]; then
  echo "Find Just Rigth Port ($count): $str"
 else
  echo "print string ($count): $str"
 fi
done

对于加法,搜了一下,本文中采用的是比较人性化的方式,其他方式总结如下:

let "n = $n + 1";: $((n = $n + 1));: $[ n = $n +1 ];n=$[ $n + 1 ];let "n++";(( n++ ));: $[ n++ ];

原文地址:https://www.cnblogs.com/xiashiwendao/p/3935522.html