for 和 while循环方式的差异
001、
[root@pc1 test]# ls a.txt [root@pc1 test]# cat a.txt ## 测试数据 1 2 3 [root@pc1 test]# sum=0 [root@pc1 test]# for i in $(seq 3); do let sum+=$i; done ## for循环,输出变量 [root@pc1 test]# echo $sum 6 [root@pc1 test]# sum=0 [root@pc1 test]# cat a.txt | while read i; do let sum+=$i; done ## while循环不能输出变量??? [root@pc1 test]# echo $sum 0

。

浙公网安备 33010602011771号