shell之数组的使用
2017-08-18 17:32
357 查看
数组 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[@]}
192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4
3) 获取数组的长度
[root@shellscript shell]# echo ${#bb[*]}
4
[root@shellscript shell]# echo ${#bb[@]}
4
编写脚本,找出数组中的最大数
#!/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
一段连续的内存空间
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[@]}
192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4
3) 获取数组的长度
[root@shellscript shell]# echo ${#bb[*]}
4
[root@shellscript shell]# echo ${#bb[@]}
4
编写脚本,找出数组中的最大数
#!/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
相关文章推荐
- bash shell数组模拟队列queue和shell数组使用技巧
- Shell编程之数组使用
- Shell 中mysql 查询以及shell字符串数组的使用
- shell 数组建立及使用技巧
- shell数组的使用
- [转]shell中的数组使用方法
- SHELL 数组:数组赋值中符号使用不正确(应该严格按"()"赋值),赋值后不能正确求出数组的长度。
- 使用shell数组重启tomcat
- shell数组使用技巧
- shell中数组的简单使用
- shell (awk)数组使用案例
- 数组-在Shell脚本中的基本使用介绍
- shell 字符串数组的使用
- shell脚本的参数设计,以及shell数组使用 demo
- 数组-在Shell脚本中的基本使用介绍
- shell数组的使用
- shell数组使用技巧
- shell数组建立和基本使用方法
- shell数组使用
- shell 数组使用