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

linux-shell-for and array code examples

步履不停
Release: 2019-06-18 16:50:05
Original
2085 people have browsed it

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
Copy after login

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
Copy after login

Array assignment

array_name[0]=value0
array_name[1]=value1
array_name[2]=value2
Copy after login

Reading the array

${array_name[index]}
Copy after login

Getting all elements of the array

${array_name[*]}
${array_name[@]}

[root@VM_158_86_centos vbird]# echo ${my_array[*]}
a b c d
Copy after login

Get the array length

${#array_name[*]}
[root@VM_158_86_centos vbird]# echo ${#my_array[*]}
4
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template