#!/bin/bash for x in `ls */.*/.*` cat $x|do echo $x while read line do c=`echo $line|awk -F'(' '{print $1}'` #echo $c i=$((i+$c)) done echo done echo $i
以上代碼有什么問(wèn)題呢? cat之后的管道會(huì)使i的值沒(méi)有被加1。
正確的方法:
復(fù)制代碼 代碼如下:
#!/bin/bash for x in `ls */.*/.*` do echo $x while read line do c=`echo $line|awk -F'(' '{print $1}'` #echo $c i=$((i+$c)) done<$x echo done echo $i