在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. STRUTS2 嵌套循环

    <!--begin 类目循环 --> <s:iterator value="categories" id='i' begin="0" step ...

  2. for循坏的穷举与迭代,while、do while循环

    for循环的穷举:所有情况走一遍,使用if筛选出符合的情况. 单位发一张150元购物卡,到超市买三种洗化用品,洗发水15元,香皂两元,牙刷5元,刚好花完150元,有多少种买法,每种买法各买几样. 百鸡 ...

  3. Doragon Kuesuto 1.15

    #include<stdio.h> #include<stdlib.h> #include<time.h> int main() { ; ; ; int actio ...

  4. Java编程思想学习笔记_6(并发)

    一.从任务中产生返回值,Callable接口的使用 Callable是一种具有泛型类型参数的泛型,它的类型参数表示的是从方法call返回的值,而且必须使Executor.submit来去调用它.sub ...

  5. Bootstrap强调相关的类

    在Bootstrap中除了使用标签<strong>.<em>等说明正文某些字词.句子的重要性,Bootstrap还定义了一套类名,这里称其为强调类名(类似前面说的“.lead” ...

  6. CSS3_边框属性之圆角

    一.border-radius是向元素添加圆角边框: border-radius的值不仅能用px单位,你还可以用百分比或者em,但兼容性目前还不太好.(都不能是负值) 1.border-radius ...

  7. mysql报关于用户密码1045(28000),几种处理方法 (zhuan)

    http://blog.itpub.net/29371470/viewspace-1409075/ http://blog.csdn.net/rosten/article/details/250658 ...

  8. iphone SE 自带视频播放器要求的视频格式转换参数

  9. 例题:打印乘法口诀。可能大家一看有点难,但只要理解for 循环嵌套,两层循环,外层循环行数,里层循环列数,搞清楚行数和列数之间的关系,就可以轻松做出这道题

    namespace 打印乘法口诀{    class Program    {        static void Main(string[] args)        {            f ...

  10. SyncServer obj