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 ...
随机推荐
- phoenxi elixir 框架几个方便的命令
1. 已有命令 mix app.start # Starts all registered apps mix app.tree # Prints the application tree mix ar ...
- FileStream读写文件
读文件示例 try { // 打开文件 FileStream fs = new FileStream("D:\\not.txt", FileMode.Open, FileAcces ...
- 【转】HP laserjet p2055dn的自动双面打印功能
原文网址:http://zhidao.baidu.com/link?url=n_NW7Qfa_7HlrEhLucdvKO43jj3SpFXJhGAfQ-WqF979jm80eUv8s1atqtxE7w ...
- MVC涉及RouteTable自定义路径
Routing 到目前为止,我们已经解决了MVC的很多问题,但忽略了最基本的最重要的一个问题:当用户发送请求时,会发生什么? 最好的答案是“执行Action 方法”,但仍存在疑问:对于一个特定的URL ...
- xml获取属性值的方法
sSqlstr += string.Format(@" and businessattr.value('(/Arch/Field[@Name=""发文单位$$" ...
- postman参数化的方法
1.准备csv格式的文件(注意第一行是是引用参数的名称) 2.编写请求,应用变量参数,并且设置断言 引用变量参数 3.把这个请求的文件夹runner一下批量执行 4.把第一步变量的csv文件在runn ...
- 简单的PL/SQl链接远程ORACLE数据库方法
简单的PL/SQl链接远程ORACLE数据库方法 PLSQL Developer新手使用教程 pasting
- hadoop Partiton中的字符串Hash函数改进
最近的MapReduce端的Partition根据map生成的Key来进行哈希,导致哈希出来的Reduce端处理任务数量非常不均匀,有些Reduce端处理的数据量非常小(几分钟就执行完成,而最后的pa ...
- 安装git之后,桌面图标出现很多的蓝色问号
今天在搞git之后,开机发现多了好多的问号: 这是因为我们在桌面创建了版本库了. 这个时候我们在系统中吧隐藏的文件夹显示出来.这个时候会看到桌面上有一个隐藏的git文件夹.把这个文件夹删除掉之后,刷新 ...
- 【POJ】2229 Sumsets(递推)
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 20315 Accepted: 7930 Descrip ...