shell-array
2013-12-06 14:11
183 查看
【shell-array】
Creating Array:
You can get the number of elements of an array by using ${#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:
参考:
1. http://hi.baidu.com/gaogaf/item/46050b15958a5225f7625c4a
2. /article/5148459.html
3. http://bash.cumulonim.biz/BashGuide(2f)Arrays.html
Creating Array:
$ names=("Bob" "Peter" "$USER" "Big Bad John") $ names=([0]="Bob" [1]="Peter" [20]="$USER" [21]="Big Bad John") # or... $ names[0]="Bob"
You can get the number of elements of an array by using ${#array[@]}:
$ array=(a b c) $ echo ${#array[@]} 3
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. /article/5148459.html
3. http://bash.cumulonim.biz/BashGuide(2f)Arrays.html
相关文章推荐
- compare array between shell and tcl
- Shell中创建序列和数组(list、array)的方法
- shell中array使用方法
- shell readarray命令
- Linux Bash shell one practice : array if else
- Shell Sort with array[]
- shell脚本中数组array常用技巧学习实践
- Shell中创建序列和数组(list、array)的方法
- Shell编程之二——read ,array,
- Linux, Mac下Shell 数组 Array 的修理工
- Shell 数组元素个数${#array[@]} 数组的所有元素${array[*]} 字符串长度${#str}
- Shell中创建序列和数组(list、array)的方法
- Shell 数组元素个数${#array[@]} 数组的所有元素${array[*]} 字符串长度${#str}
- Shell - 简明Shell编程07 - 数组(Array)
- shell脚本中数组array常用技巧学习实践
- Shell 数组元素个数${#array[@]} 数组的所有元素${array[*]} 字符串长度${#str}
- 5-4array统计不同类型shell的数量
- shell中的array数组
- Shell脚本编程——数组(array)
- @shell脚本中数组array常用技巧学习实践@