1、定義數組
說明:一對括號表示是數組,數組元素用“空格”符號分割開。
實例:
[test@test]$ a=(1 2 3 4 5)
[test@test]$ echo $a
1
2、讀取數組元素
形式:
(1)讀取某個元素
[test@test]$ a=(1 2 3 4 5)
[test@test]$ echo ${a[2]}
3
(2)讀取全部元素
[test@test]$ a=(1 2 3 4 5)
[test@test]$ echo ${a[*]}
1 2 3 4 5
3、刪除數組元素
說明:使用unset命令
形式:
[test@test]$ a=(1 2 3 4 5)
[test@test]$ unset a[1]
[test@test]$ echo ${a[*]}
1 3 4 5
4、數組元素賦值
形式:
[test@test]$ a=(1 2 3 4 5)
[test@test]$ a[1] = 100
[test@test]$ echo ${a[*]}
1 100 3 4 5
5、獲得數組長度
形式:length =${#a[@]}
[test@test]$ a=(1 2 3 4 5)
[test@test]$ echo
${#a[@]}
5