This is where I need to to populate the SITE1= SITE2= SITE3= variables using the data in site_names, so the variables require to be available throughout the script like this:
do a web search for 'ash array' or 'busybox array' or something like that and click any link that says stackexchange
there are 1000 ways to do what your asking... and you are much better off learning how to fish...
no success? get creative 'linux script numered variables' etc. etc. etc.
i.e.
eval $(ls -1 /usr/share/zoneinfo/America/. | while read this; do num=$((num + 1)); echo STATE${num}=$this; done)
good luck!
( a simpler solution is to use iterative logic and handle each line as it comes... without numbered variables check @vgaetera s masterpiece opkg-script.sh for ideas )
I've been fishing all day @anon50098793 ! I wouldn't be posting here if I did catch something!
The main issue I have is getting the data into the SITE1 SITE2 SITE3 variables. Easy to do if you write the data to file then retrieve into these variables, but using the data from a variable is where I'm getting burnt!
It's not clear why can't you place the code in a loop and loop through the list of sites.
Looks like you are trying to use an array, which you don't actually need.
In this case, the code suggested by @anon50098793 appears to be the most appropriate.
If you really need to index lines:
SITES="/tmp/sites"
for I in $(seq "$(sed -n -e "\$=" "${SITES}")")
do echo "${I}:$(sed -n -e "${I}p" "${SITES}")"
done
It was my brain that needed sorting, I tried to simplify things by not writing more code than I required by introducing a while loop which didn't agree to incrementing the SITEx variables withing the loop.
I settled for outputting the data to 3x /tmp files:
echo "$sorted_region_data" | while read -r output ; do echo "$output" | cut -d "," -f1 ; done > "$CONFIGDIR/sites.name"
echo "$sorted_region_data" | while read -r output ; do echo "$output" | cut -d "," -f2 ; done > "$CONFIGDIR/sites.id"
echo "$sorted_region_data" | while read -r output ; do echo "$output" | cut -d "," -f3 ; done > "$CONFIGDIR/sites.other"
then loaded the SITEx SITE_IDx SITE_DATAx variables using sed: