数组 Array
一段连续的内存空间
1) 定义数组
[root@shellscript shell]# aa[0]=martin
[root@shellscript shell]# aa[1]=jerry
[root@shellscript shell]# aa[2]=mike
[root@shellscript shell]# aa[10]=alice
[root@shellscript shell]# bb=(192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4)
2) 调用数组的值
[root@shellscript shell]# echo ${bb[2]}
192.168.1.3
[root@shellscript shell]# echo ${bb[1]}
192.168.1.2
[root@shellscript shell]# echo ${bb[*]}
192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4
[root@shellscript shell]# echo ${bb[@]}
3) 获取数组的长度
[root@shellscript shell]# echo ${#bb[*]}
4
[root@shellscript shell]# echo ${#bb[@]}
编写脚本,找出数组中的最大数
#!/bin/bash
#
aa=(14 543 64 235 76 345 765)
max=${aa[0]}
for i in `seq 6`; do
if [ $max -lt ${aa[$i]} ]; then
max=${aa[$i]}
fi
done
echo $max
本文转自 北冥有大鱼 51CTO博客,原文链接:http://blog.51cto.com/lyw168/1957422,如需转载请自行联系原作者