#!/bin/bash
for ((i=1;i<=5;i++))
do
userlist[$i]="skyuser"$i
echo ${userlist[$i]}
done
echo ${userlist[*]}
for user in ${userlist[*]}
do
echo $user
done
複製代碼
初始化數組centos
my_array=(a b c d)
[root@VM_158_86_centos vbird]# my_array=(a b c d)
[root@VM_158_86_centos vbird]# echo ${my_array[*]}
a b c d
複製代碼
數組賦值數組
array_name[0]=value0
array_name[1]=value1
array_name[2]=value2
複製代碼
讀取數組bash
${array_name[index]}
複製代碼
獲取數組的全部元素ui
${array_name[*]}
${array_name[@]}
[root@VM_158_86_centos vbird]# echo ${my_array[*]}
a b c d
複製代碼
獲取數組長度spa
${#array_name[*]}
[root@VM_158_86_centos vbird]# echo ${#my_array[*]}
4
複製代碼