bash 数组
第一种:
area[11]=23
area[22]=25
echo "area[11]=${area[11]}"
第二种:
area2=(zero one two three four)
echo "area2[0]=${area[0]}"
第三种:
area3([11]=23 [22]=25)
echo "area[11]=${area[11]}"
#!/bin/bash
line[1]="I do not know which to prefer,"
line[2]="The beauty of inflections"
line[3]="Or the beauty of innuendoes,"
line[4]="The blackbird whistling"
line[5]="Or just after."
attrib[1]="Wallace Stevens"
attrib[2]="\"Thirteen Ways of Looking at a Blackbird\""
echo
for index in 1 2 3 4 5
do
printf "%s\n" "${line[index]}"
done
echo
for index in 1 2
do
printf "%s\n" "${attrib[index]}"
done
echo
exit 0
#!/bin/bash
array=(zero one two three four five)
echo ${array[0]}
echo ${array:0}
echo ${array[1]:1} 元素的参数扩展(除去多小个字符)
echo ${#array[0]} 数组第一个元素的长度
echo ${#array[*]} (echo ${#array[@]})数组中元素的个数
echo ${array[*]:0}(echo ${array[@]:0})提取所有元素
echo ${array[*]:1}(echo ${array[@]:1})提取array[0]元素后面所有元素
echo ${array[*]:2:1} 提取array[2]元素后面1个元素,即arra[2]
echo ${array[*]#f*e}匹配表达式作用于所有的数组的元素,去除匹配!!