在shell脚本中,除了通常使用的shell变量外,有时也需要复杂的数据结构去实现一些功能,这里简单说明一下shell数组的使用方法:

初始化方法

_array_name[0]="random"
_array_name[1]="random1"
_array_name[2]="random2"

或者

_array_name=( 1 2 3 )

引用数组元素

${_array_name[2]}

判断数组长度

length=${#_array_name[@]}

遍历数组

for i in "${_array_name[@]}"
do
echo $i
done

index=`expr ${#_array_name[@]} - 1`
name=random
while [ $index -ge 0 ]
do
if [ "$name"x = "${_array_name[$index]}"x ]; then
echo "do something: $name"
else
echo "this is ${_array_name[$index]}"
fi
index=`expr $index - 1`
done

shell中的数组的更多相关文章

  1. Shell中的数组及其相关操作

    http://blog.csdn.net/jerry_1126/article/details/52027539 Shell中数据类型不多,比如说字符串,数字类型,数组.数组是其中比较重要的一种,其重 ...

  2. shell中的函数、shell中的数组、告警系统需求分析

    7月16日任务 20.16/20.17 shell中的函数20.18 shell中的数组20.19 告警系统需求分析 20.16/20.17 shell中的函数 函数就是一个子shell就是一个代码段 ...

  3. linux shell 中的数组的取值 遍历 替换 删除操作

    引言 在Linux平台上工作,我们经常需要使用shell来编写一些有用.有意义的脚本程序.有时,会经常使用shell数组.那么,shell中的数组是怎么表现的呢,又是怎么定义的呢?接下来逐一的进行讲解 ...

  4. Linux centosVMware shell中的函数、shell中的数组、

    一.shell中的函数 函数就是把一段代码整理到了一个小单元中,并给这个小单元起一个名字,当用到这段代码时直接调用这个小单元的名字即可. 格式: function _name() { command ...

  5. 九 Shell中的数组

    数组:用一个变量存储一组数据,并能够对这组数据中的某一个数据单独操作. 数组的类型:一维数组.二维数组.多维数组 变量的类型 Shell中默认无类型 变量的值默认均视为文本 用在数字运算中时,自动将其 ...

  6. Linux Shell中的数组及遍历 转

    转自:http://www.linuxidc.com/Linux/2011-09/42929.htm 在Linux下使用shell的时候,为方便起见,偶尔会用到一下数组.数组的申明方式是: array ...

  7. shell中一维数组值得获取

    (1)数组的定义 root@tcx4440-03:~# a=(1 2 3 4) root@tcx4440-03:~# echo ${a[1]}2 root@tcx4440-03:~# a[0]=1ro ...

  8. shell中的函数 shell中的数组 告警系统需求分析

     

  9. shell中遍历数组的几种方式

    #!/bin/bash arr=( '你好') length=${#arr} echo "长度为:$length" # for 遍历 for item in ${arr[*]} d ...

随机推荐

  1. 2013/7/16 HNU_训练赛4

    CF328B Sheldon and Ice Pieces 题意:给定一个数字序列,问后面的数字元素能够组成最多的组数. 分析:把2和5,6和9看作是一个元素,然后求出一个最小的组数就可以了. #in ...

  2. poj1927Area in Triangle

    链接 物理渣只能搜题解了.. 分三种情况 1.len>=a+b+c 2.len<内切圆半径 圆的面积是最大的 -->以len为周长的圆 3.看这篇http://blog.sina.c ...

  3. create table xxx as select 与 create table xxx like

    create table xxx )       | NO   | PRI | NULL    | auto_increment | | Name       | varchar() | NO   | ...

  4. svn设置提交忽略某些文件或文件夹

    在svn客户端,想设置忽略提交.class文件,通过 properties > New > Other 添加一个忽略的属性,,还是不行:部分屏蔽了,部分class还是在列表中 再次参考了一 ...

  5. Winform_ComBox三种赋值方式

    第一种方法: DataTable dt = new DataTable(); dt.Columns.Add( "name" ); dt.Columns.Add( "val ...

  6. What is the difference between extensibility and scalability?

    You open a small fast food center, with a serving capacity of 5-10 people at a time. But you have en ...

  7. vim 学习记录2

    当前行进行替换:s/XXX/YYY/gXXX是需要替换的字符串,YYY是替换后的字符串. 全局替换:% s/XXX/YYY/g. 对指定部分进行替换用V进入visual模式,再进行:s/XXX/YYY ...

  8. HTTP Status 500 - An exception occurred processing at line 35

    HTTP Status 500 - An exception occurred processing JSP page /manage/addCategory.jsp at line 35 type ...

  9. icp算法的一些参考资料

    1.综述:迭代最近点算法综述,介绍了svd分解和四元数法,其中 svd法:http://blog.csdn.net/kfqcome/article/details/9358853 四元数法:http: ...

  10. div contenteditable placeholder

    contenteditable型的编辑框,实现placeholder的方式有两种 第一种,Css的实现方式: <!DOCTYPE html> <html lang="en& ...