— http://blog.fallseir.com/2008/10/array_in_shell/
- $ arr=(123 34 3 5)
- $ echo $arr
- > 123
- $ echo ${arr[1]}
- > 34
- $ echo ${arr[@]}
- > 123 34 3 5
- $ echo ${#arr[@]}
- > 3
- $ echo ${#arr[3]}
- > 1
- $ echo ${arr[@]:1:2}
- > 34 3
- $ echo ${arr[@]:2}
- > 3 5
- $ echo ${arr[@]::2}
- > 123 34
-
- 参考 http:
-
- array 的模拟操作
- – http:
- push:
- array=(”${array[@]}” $new_element)
-
- pop:
- array=(${array[@]:0:$((${#array[@]}-1))})
-
- shift:
- array=(${array[@]:1})
-
- unshift
- array=($new_element “${array[@]}”)
-
- function del_array {
- local i
- for (( i = 0 ; i < ${#array[@]} ; i++ ))
- do
- if [ "$1" = "${array[$i]}” ] ;then
- break
- fi
- done
- del_array_index $i
- }
-
- function del_array_index {
- array=(${array[@]:0:$1} ${array[@]:$(($1 + 1))})
- }