Home  >  Article  >  Operation and Maintenance  >  linux-shell-for and array code examples

linux-shell-for and array code examples

步履不停
步履不停Original
2019-06-18 16:50:052026browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more