I'd like to use a variable
variablenaam
for using in a loop.
I tried for hours but can't make it work.
My experiment in bash on a RPi 4 with the latest Raspbian.
I like to make the use of xstack1 and xstack2 variable so i can use them in a loop. Example below has two stacks I like to use in a loop
so I have to make the variable xstack variable
.
clear
xstack1=( domoticz dashboard dashticz nodered )
xstack2=( x y z )
printf "Original value xstack1[*]= ${xstack1[*]}" # this gives all the entries of x, this must be the result at the end by choose for xstack1 = q=1
printf "\n\n Lets Start, try to make xstack variable"
q=1 # we want tot retrieve all values of xstack1
qq=$(eval "echo xstack${q}")
printf "\nvariablenaame of xstack1 = $qq" # so far so good
printf "\n"
qqq=$(eval "echo $qq[*]") #now add the all parameter
printf "\nvariablenaam with wildcard must do show all values but dont= $qqq" #only one value
printf "\n\n"
qqqq=$(eval "echo \$$qqq")
printf "last try and does not work, i only get one value= ${qqqq}\n"
This is The code where i want to use it. you see for similar block with stack1-4 and i think this can be one block with a variable name for xstack1-4. This xstack is a array and i think that gives the problem. These blocks are working perfectly, but not written perfectly :-)
local t_maxkolom=9
local t_mitem=1
local t_stack=0
while [ $t_stack -lt $t_maxkolom ]
do
local t_gitem=0
local t_sp='%31s'
if [ -z "${stack1[$t_stack]}" ]; then printf $t_sp && printf "${normal}"; else
printf "${number} $((t_mitem + $t_gitem )))${normal} Toevoegen " && printf '%-16s' "${stack1[$t_stack]}" && printf "${normal}"
fi
local t_sp='%32s'
local t_gitem=$((t_gitem + 10))
if [ -z "${stack2[$t_stack]}" ]; then printf $t_sp && printf "${normal}"; else
printf "${number} $((t_mitem + $t_gitem )))${normal} Toevoegen " && printf '%-16s' "${stack2[$t_stack]}" && printf "${normal}"
fi
local t_sp='%32s'
local t_gitem=$((t_gitem + 10))
if [ -z "${stack3[$t_stack]}" ]; then printf $t_sp && printf "${normal}"; else
printf "${number} $((t_mitem + $t_gitem )))${normal} Toevoegen " && printf '%-16s' "${stack3[$t_stack]}" && printf "${normal}"
fi
local t_sp='%32s'
local t_gitem=$((t_gitem + 10))
if [ -z "${stack4[$t_stack]}" ]; then printf $t_sp && printf "${normal}\n"; else
printf "${number} $((t_mitem + $t_gitem )))${normal} Toevoegen " && printf '%-16s' "${stack4[$t_stack]}" && printf "${normal}"
printf "\n"
fi
t_stack=$(( $t_stack + 1 ))
t_mitem=$((t_mitem + 1))
done
With this code I generate the menu items for my docker app

Asked by pvk
(5 rep)
Feb 11, 2023, 03:50 PM
Last activity: Feb 15, 2023, 10:18 AM
Last activity: Feb 15, 2023, 10:18 AM