linux-shell-for和數(shù)組代碼示例

linux-shell-for和數(shù)組代碼示例

#!/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

初始化數(shù)組

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

數(shù)組賦值

array_name[0]=value0 array_name[1]=value1 array_name[2]=value2

讀取數(shù)組

${array_name[index]}

獲取數(shù)組的所有元素

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

獲取數(shù)組長(zhǎng)度

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

更多linux相關(guān)技術(shù)文章,請(qǐng)?jiān)L問(wèn)Linux教程欄目進(jìn)行學(xué)習(xí)!

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊13 分享
站長(zhǎng)的頭像-小浪學(xué)習(xí)網(wǎng)月度會(huì)員