:name:2}"
#关联数组的删除
echo "del before link arr2 is ${link_arr2
}"
unset link_arr2[age]
echo ""del after link arr2 is ${link_arr2
}
unset link_arr
echo "del all arr ${link_arr
}"
#获得所有的索引值
echo "link arr2 indexs : ${link_arr2
}" 结果:
comm_arr1 len is 5
comm_arr2 len is 3
comm_arr1 all elem is : 1 2 3 4 5
comm_arr2 all elem is :6 7 8
comm_arr[4] = 5
comm_arr[2] = 8
comm_arr[100] =
3 in comm_arr is replace 200 : 1 2 200 4 5
comm_arr is 1 2 3 4 5
7 in comm_arr2 is replace 9 and modify comm_arr2
comm_arr2 is 6 9 8
splite comm_arr 1-3 is : 2 3 4
sub arr : len = 3 , elems is : 3 4 5
del before, comm_arr is 1 2 3 4 5
del a elem
del after, comm_arr is 2 3 4 5
del all arr
del after, comm_arr is
indexs is 0 1 2
link arr len: 2
link arr2 len: 3
link arr index=apple, elem is 10$
link arr2 index=name, elem is zhangsan
link arr index=name not exist, but no error,
apple is 100Y 10$
link_arr2 is zhangsan 20 m
link arr2 zhangsan is replace lisi, lisi 20 m
link arr2 is zhangsan 20 m
link arr2 age-name: zhangsan 20
del before link arr2 is zhangsan 20 m
del after link arr2 is zhangsan m
del all arr
link arr2 indexs : zhangsan m 四、总结
【1】与C语言的数组相比较
(1)C语言的数组的下标值只能是整数; 而shell的数组的下标值可以是字符串
(2)C语言的数组的内容是一组相同类型的元素; 而shell数组的内容可以是混杂的
(3)C语言的数组的大小在声明的时候就必须指定,并且大小不能扩增; 而shell数组声明不需要指定大小,直接添加元素即可
(4)访问C语言的数组时, 下标值不能越界, 否则出错; 而shell数组没有限制,访问不存在的下标的元素时返回空,而不出错
(5)C语言数组没有shell数组那么多操作