shell中的数组
在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中的数组的更多相关文章
- Shell中的数组及其相关操作
http://blog.csdn.net/jerry_1126/article/details/52027539 Shell中数据类型不多,比如说字符串,数字类型,数组.数组是其中比较重要的一种,其重 ...
- shell中的函数、shell中的数组、告警系统需求分析
7月16日任务 20.16/20.17 shell中的函数20.18 shell中的数组20.19 告警系统需求分析 20.16/20.17 shell中的函数 函数就是一个子shell就是一个代码段 ...
- linux shell 中的数组的取值 遍历 替换 删除操作
引言 在Linux平台上工作,我们经常需要使用shell来编写一些有用.有意义的脚本程序.有时,会经常使用shell数组.那么,shell中的数组是怎么表现的呢,又是怎么定义的呢?接下来逐一的进行讲解 ...
- Linux centosVMware shell中的函数、shell中的数组、
一.shell中的函数 函数就是把一段代码整理到了一个小单元中,并给这个小单元起一个名字,当用到这段代码时直接调用这个小单元的名字即可. 格式: function _name() { command ...
- 九 Shell中的数组
数组:用一个变量存储一组数据,并能够对这组数据中的某一个数据单独操作. 数组的类型:一维数组.二维数组.多维数组 变量的类型 Shell中默认无类型 变量的值默认均视为文本 用在数字运算中时,自动将其 ...
- Linux Shell中的数组及遍历 转
转自:http://www.linuxidc.com/Linux/2011-09/42929.htm 在Linux下使用shell的时候,为方便起见,偶尔会用到一下数组.数组的申明方式是: array ...
- shell中一维数组值得获取
(1)数组的定义 root@tcx4440-03:~# a=(1 2 3 4) root@tcx4440-03:~# echo ${a[1]}2 root@tcx4440-03:~# a[0]=1ro ...
- shell中的函数 shell中的数组 告警系统需求分析
- shell中遍历数组的几种方式
#!/bin/bash arr=( '你好') length=${#arr} echo "长度为:$length" # for 遍历 for item in ${arr[*]} d ...
随机推荐
- HIHO 线段树(单点)
#include <stdio.h> #include <string.h> #include <math.h> #include <iostream> ...
- http1.1和http1.0区别
http1.1和服务器建立连接可以获得多个资源 http1.0和服务器建立连接可以获取一个值
- mysql 检查字符串是否包含子串
1.使用substring_index(src,target,index) 从src的开头查找第index个target.返回的substring为从src的开头到第num个target这段字符串.比 ...
- 26个Jquery使用小技巧
下面列出了一些Jquery使用技巧.比如有禁止右键点击.隐藏搜索文本框文字.在新窗口中打开链接.检测浏览器.预加载图片.页面样式切换.所有列等高.动态控制页面字体大小.获得鼠标指针的X值Y值.验证元素 ...
- Activity中与ListActivity中使用listview区别
Activity中与ListActivity中使用listview区别 一.Activity中与ListActivity中使用listview区别(本身没多大区别,只是ListActivity在lis ...
- 【转载】Linux系统,设置Oracle开机启动,待整理
http://www.cnblogs.com/mophee/archive/2013/06/03/3115805.html
- hiho1091_clicker背包问题
问题 类似有限背包问题,题目链接:clicker 实现 #include<stdio.h> #include<cmath> #include<iostream> # ...
- phalcon: 缓存片段,文件缓存,memcache缓存
几种缓存,需要用到前端配置,加后端实例配合着用 片段缓存: public function indexAction() { //渲染页面 $this->view->setTemplateA ...
- 设置segue跳转页面
第二种是利用ViewController与ViewController之间,拖拽添加segue 方法中提到的设置segue的identifier界面 在.h文件中声明 - (IBAction)goto ...
- Rest接口中正则表达式
匹配所有字符: @Path("/server/{urlParam: .*}")