shell编程问题
array=(12231576548910)echo${array[@]}len=${#array[@]}i=0while["$i"-lt"$len"]dok=0j=$i...
array=(12 23 15 7 6 5 4 8 9 10)
echo ${array[@]}
len=${#array[@]}
i=0
while [ "$i" -lt "$len" ]
do
k=0
j=$i+1
while [ "$j" -lt "$len" ]
do
if [ ${array[$i]} -gt ${array[$j]} ];then
k=${array[$i]}
{array[$i]}=${array[$j]}
{array[$j]}=$k
fi
j=$j+1
done
i=$i+1
done
echo ${array[@]}
报错./y: line 10: [: 0+1: integer expression expected
./y: line 6: [: 0+1: integer expression expected
while if 中的空格都加了 展开
echo ${array[@]}
len=${#array[@]}
i=0
while [ "$i" -lt "$len" ]
do
k=0
j=$i+1
while [ "$j" -lt "$len" ]
do
if [ ${array[$i]} -gt ${array[$j]} ];then
k=${array[$i]}
{array[$i]}=${array[$j]}
{array[$j]}=$k
fi
j=$j+1
done
i=$i+1
done
echo ${array[@]}
报错./y: line 10: [: 0+1: integer expression expected
./y: line 6: [: 0+1: integer expression expected
while if 中的空格都加了 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询