Home > Article > Operation and Maintenance > linux-shell-for and array code examples
#!/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
Initializing the array
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 assignment
array_name[0]=value0 array_name[1]=value1 array_name[2]=value2
Reading the array
${array_name[index]}
Getting all elements of the array
${array_name[*]} ${array_name[@]} [root@VM_158_86_centos vbird]# echo ${my_array[*]} a b c d
Get the array length
${#array_name[*]} [root@VM_158_86_centos vbird]# echo ${#my_array[*]} 4
For more Linux-related technical articles, please visit the Linux Tutorial column. study!
The above is the detailed content of linux-shell-for and array code examples. For more information, please follow other related articles on the PHP Chinese website!