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 ...
随机推荐
- ubuntu安装jdk-6u45-linux-x64-rpm.bin
1. 参考网址: http://www.xuebuyuan.com/2070575.html http://blog.csdn.net/csusunxgg/article/details/895602 ...
- 抓包工具__Windows
我常使用的: 1. SoftPerfect Network Protocol Analyzer 2. fiddler . fiddler2 3.
- mysql 内连接 左连接 右连接 外连接
mysql> desc student;+-------+-------------+------+-----+---------+-------+| Field | Type | Null | ...
- C10K及C100K问题探讨 & 怎么应对大流量大并发
首先开宗明义,离开业务单独讨论并发,都是扯淡. 就像 https://www.zhihu.com/question/20493166/answer/15998053 这里面说的 谈并发必然要谈业务,空 ...
- Java用通配符 获得泛型的协变和逆变
Java对应泛型的协变和逆变
- Make 教程
Make 命令教程 原文作者: 阮一峰 原文链接:http://www.ruanyifeng.com/blog/2015/02/make.html (在原文基础上稍作修改) 代码变成可执行文件,叫做编 ...
- git使用技巧
git使用技巧 转载自:http://172.17.144.8/iceway.zhang/shares/201604/201604_git_tips.md.html 我们在工作中几乎每天都会用到git ...
- kvm相关文章
配置KVM虚拟机的网络 Bridge和Nat方式http://www.it165.net/os/html/201503/12231.html KVM虚拟机网络配置 Bridge方式,NAT方式 htt ...
- Html_页面的高度宽度等
offsetTop 指元素距离上方或上层控件的位置,整型,单位像素. offsetLeft 指元素距离左方或上层控件的位置,整型,单位像素. offsetWidth 指元素控件自身的宽度,整型,单位像 ...
- Sublime Text 3使用技巧
工欲善其事必先利其器,用了很多编辑器,pycharm.Eclipse.notepad++.ultra edit等等,要么是太卡,要么是太简陋 论性感,论轻便,论功能,我选Sublime Text 参考 ...