shell-array
【shell-array】
Creating Array:
$ names=("Bob" "Peter" "$USER" "Big Bad John")
$ names=([]="Bob" []="Peter" []="$USER" []="Big Bad John")
# or...
$ names[]="Bob"
You can get the number of elements of an array by using ${#array[@]}:
$ array=(a b c)
$ echo ${#array[@]}
There is also a second form of expanding all array elements, which is "${arrayname[*]}". This form is ONLY useful for converting arrays into a single string with all the elements joined together. The main purpose for this is outputting the array to humans:
$ names=("Bob" "Peter" "$USER" "Big Bad John")
$ echo "Today's contestants are: ${names[*]}"
Today's contestants are: Bob Peter lhunath Big Bad John
Associative Arrays
To create an associative array, you need to declare it as such (using declare -A).
$ declare -A fullNames
$ fullNames=( ["lhunath"]="Maarten Billemont" ["greycat"]="Greg Wooledge" )
$ echo "Current user is: $USER. Full name: ${fullNames[$USER]}."
Current user is: lhunath. Full name: Maarten Billemont.
参考:
1. http://hi.baidu.com/gaogaf/item/46050b15958a5225f7625c4a
2. http://www.cnblogs.com/chengmo/archive/2010/09/30/1839632.html
3. http://bash.cumulonim.biz/BashGuide(2f)Arrays.html
shell-array的更多相关文章
- Linux, Mac下Shell 数组 Array 的修理工
我的测试基本都是在Mac,及Unix环境下测试的,如无特别注明,默认就是Mac 不论你看到这篇随笔是被shell array的奇淫巧技,还是发现shell array就在一对{}里面就可以做那么多勾当 ...
- PHP安全编程:shell命令注入(转)
使用系统命令是一项危险的操作,尤其在你试图使用远程数据来构造要执行的命令时更是如此.如果使用了被污染数据,命令注入漏洞就产生了. exec()是用于执行shell命令的函数.它返回执行并返回命令输出的 ...
- shell 3数组
shell数组 shell支持一维数组(不支持多维数组),并且没有限定数组的大小. 定义数组 shell中,用括号来表示数组,数组元素用空格分隔,下标从0开始,元素的类型 方式1 数组名=(值1 值2 ...
- shell编程系列21--文本处理三剑客之awk中数组的用法及模拟生产环境数据统计
shell编程系列21--文本处理三剑客之awk中数组的用法及模拟生产环境数据统计 shell中的数组的用法: shell数组中的下标是从0开始的 array=("Allen" & ...
- shell编程系列4--有类型变量:字符串、只读类型、整数、数组
shell编程系列4--有类型变量:字符串.只读类型.整数.数组 有类型变量总结: declare命令和typeset命令两者等价 declare.typeset命令都是用来定义变量类型的 decla ...
- Java 部分排序算法
. import java.io.*;import java.math.*;import java.util.*;public class Algr{ public static int array[ ...
- A Mysql backup script
UseCentOS can help IT managers to get rid of the boring learning methods, quick grasp Linux technolo ...
- zabbix discovery
preface(见面礼): 仅扫tcp端口: netstat -tnlp|egrep -i "$1"
- 算法(第四版)C# 习题题解——2.1
写在前面 整个项目都托管在了 Github 上:https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp 这一节内容可能会用到的库文件有 ...
- 希尔排序算法的php实现
虽然现在各种程序语言都有其各自强大的排序库函数,但是这些底层实现也都是利用这些基础或高级的排序算法. 理解这些复杂的排序算法还是很有意思的,体会这些排序算法的精妙~ 一.希尔排序(shell sort ...
随机推荐
- Sprint第一个冲刺(第二天)
一.Sprint介绍 今天我们完成了欢迎界面及美化的任务,即完成了此次整个Sprint的百分之七,登录界面及美化.注册界面(管理员).注册界面(餐厅员工)和注册界面(消费者),这几个任务也在进行时.这 ...
- asp.net如何判断服务器上的目录或文件是否存在
asp.net判断服务器上的目录或文件是否存在!(实例) // ======================================================= [判断文件是否存在] u ...
- 洛谷P2192HXY玩卡片
题目大意 给你n个数,只包括5和0. 从中取一些数,要求组成的数是90的倍数. 如: 4 5 0 5 0 结果是0 题解 90=9*10,如果一个是90的倍数一定末尾有0,那么这个 数一定是10的倍数 ...
- jasmine 使用
1. 下载浏览器运行测试包 https://github.com/jasmine/jasmine/releases 2. 解压,运行包含的测试 SpecRunner.html 3. 测试结果 ...
- pycaffe + anaconda2 + python2.7.配置
1.首先要把caffe-windows用VS2013编译好(这一步很多门道,很麻烦很多坑),编辑props文件,使python支持选项开启,单独编译pycaffe项目就可以 2.将生成的在build/ ...
- java多线程(2) 线程同步
我们对线程访问同一份资源的多个线程之间,来进行协调的这个东西,就是线程同步. 例子1:模拟了多个线程操作同一份资源,可能带来的问题: package com.cy.thread; public c ...
- 【转】Jmeter测试报表相关参数说明
Jmeter测试报表相关参数说明 采用Jmeter测试工具对web系统作的负载测试,得出的响应报表,数据比较难懂,现作一具体说明. 以下是在一次具体负载测试中得出的具体数值,测试线程设置情况为:线程数 ...
- 按键精灵saystring无法使用的几种解决方案
1.当输入密码无法使用“SayString”.“Ctrl+V”时,改用“KeyPress”的方法 戏谷游戏的登录画面,“密码输入” 是会挡按键精灵的“SayString”这指令,还有“Ctrl+V”贴 ...
- 第五章 MyEclipse配置hadoop开发环境
1.首先要下载相应的hadoop版本的插件,我这里就给2个例子: hadoop-1.2.1插件:http://download.csdn.net/download/hanyongan300/62381 ...
- 编译hostapd时,出现错误:/usr/bin/ld: cannot find -lnl
book@ubuntu:/work/project/wifi/04.hostapd/hostapd-2.0/hostapd$ make /usr/bin/ld: cannot find -lnl co ...