简体   繁体   中英

bash array + how to set variable in bash array

we set the "list" variable with sdb - sdz range

# MAX=z
# list=$(eval echo sd{b..$MAX})
# echo $list
sdb sdc sdd sde sdf sdg sdh sdi sdj sdk sdl sdm sdn sdo sdp sdq sdr sds sdt sdu sdv sdw sdx sdy sdz

until now its ok

now we set the $list in array as the follwing

#array=( echo $list )

but when we print the first value of the array we get "echo"

#echo ${array[0]}
echo

what is wrong here?

expected results:

#echo ${array[0]}
sdb


#echo ${array[1]}
sdc

#echo ${array[2]}
sdc

or

# echo  "${list[counter++]}"
$ max=z
$ list=( $(eval echo sd{b..$max}) )
$ echo "${list[*]}"
sdb sdc sdd sde sdf sdg sdh sdi sdj sdk sdl sdm sdn sdo sdp sdq sdr sds sdt sdu sdv sdw sdx sdy sdz
$ echo "${list[1]}"
sdc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM