Marius Marius - 2 months ago 7
Bash Question

Can't fill bash array

I'm running Ubuntu 14.04 and am trying to fill an array in a shell script so that I can loop over it and utilize its contents to fill a text file. However, there's a snag: it doesn't seem to be filling.

I've simplified the larger script that I'm working with down to the essential issue, reprinted below:

WL_START=1
WL_END=5
WL_INC=1
wl_range=$(seq $WL_START $WL_INC $WL_END)

declare -a WL

for i in $wl_range # loop through sequence and fill array
do
WL[$i]=${wl_range[$i]}
done

echo $wl_range
echo ${wl_range[1]}
echo $WL
echo ${WL[1]}


However, my output looks like this:

1 2 3 4 5

empty line

empty line

empty line

Any ideas? I know that people say to just use seq to fill the array, but I had the same problem there as well.

Answer

Too much work.

WL=($(seq $WL_START $WL_INC $WL_END))
Comments