方法一:
sum=0
arr=”1 2 3″
for var in $arr
do
echo $var
((sum+=$var))
done
echo $sum
方法二:
arr=(“1″ “b” “a” “c”)
for i in ${arr[@]};
do
echo $i
done
方法三:
len=${#arr[@]}
for((i=0;i<len;++i))
do
echo ${arr[$i]}
done
方法一:
sum=0
arr=”1 2 3″
for var in $arr
do
echo $var
((sum+=$var))
done
echo $sum
方法二:
arr=(“1″ “b” “a” “c”)
for i in ${arr[@]};
do
echo $i
done
方法三:
len=${#arr[@]}
for((i=0;i<len;++i))
do
echo ${arr[$i]}
done