#!/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
以上代碼有什么問題呢? cat之后的管道會使i的值沒有被加1。
正確的方法:
復制代碼 代碼如下:
#!/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