Use positional parameters in loop / while syntax in whiptail

I like to �optimize� / make more like a real program my bash script by replacing repetitious code which utilizes positional parameters.

I am having two issues I cannot solve and would appreciate some assistance with resolving them.

a) how to modify the whiptail checklist �menu� and insert it into whiptail
b) how to replace each case with common code checking only even positional parameters

Each and every choice selected is plain command hence a common function.

I did try the while / do done but it did not echo positional parameters


  
 whiptail_DEBUG_BASE_arg(){
 
 
 # BUG did not print positional parameters
 x=1
 while [ $x -le 5 ]
 do
   echo "Welcome {${x}} times"
   x=$(( $x + 1 ))
 done
 pause
 
 
 whiptail --title "$1" \
 --checklist \
 --separate-output "Choose:" 20 78 15 \
 "$2" "$3" on \
 "$4" "$5" off \
 "$6" "$7" off \
 "$8" "$9" off \
 "${10}" "${11}" off \
 "${12}" "${13}" off \
 "${14}" "${15}" off \
 "${16}" "${17}" off \
 "${18}" "${19}" off \
 "${20}" "${21}" off \
 "${22}" "${23}" off \
 "${24}" "${25}" off \
 "${10}" "${11}" off \
 "${12}" "${13}" off \
 "${14}" "${15}" off \
 "${16}" "${17}" off \
 "${18}" "${19}" off \
 "${20}" "${21}" off \
 "${22}" "${23}" off \
 "${24}" "${25}" off \
  2>results
 
 
 while read choice
 do
         case $choice in
                 $2)
                 $2   # execute command 

                ;;
                 $4)
                 $4
                 ;;
                 $6)
                 $6
                 ;;
                 $8)
                 $8
                 ;;
                 ${10})
                 ${10}
                 ;;
                 ${12})
                 ${12}
                 ;;
                 ${14})
                 ${14}
                 ;;
                 *) echo "Invalid entry!"
                 ;;
 # BUG echo "$choice"
         esac
 done < results
 pause
 
 
  p { margin-bottom: 0.1in; line-height: 115%; }




Regarding the loop:

Your method would need another redirection. In bash this can be done with

x=1
 while [ $x -le 5 ]
 do
   echo "${!x}"
   x=$(( $x + 1 ))
 done

It is more common to print $1 and shift the parameters to the left ($2 -> $1, $3 -> $2,...)

x=1
while [ $x -le $# ]
do
  echo "${1}"
  x=$(( $x + 1 ))
  shift
done

Most easy: loop over the argument values with a for loop

for arg in "$@"
do
  echo "$arg"
done

In a for loop the argument values are the default:

for arg
do
   echo "${arg}"
done

Here is partial solution for b item.

I need to take a very hard look at the whiptail - "choice" is the key.
The attached code "loops" thru all checked sections in checklist - they are all even positioning

parameters and there is no need to recheck that.

echo "START read all positionining parameters" 
pause
 while read choice
 do
 echo $choice
 echo "@line $LINENO"
 pause 
 echo "process command $LINENO" 
 $choice
 pause      # wiil not wait for keyboard 
 done < results
 echo "END read all positionining parameters" 
pause 






Moderator comments were removed during original forum migration.