I'd never used select
before, and I've also never used bash arrays before, so here's v0.1 of a menu that cycles through 25 items at a time. The number of items at a time is set up top as howmany. You'd need to add logic for circling back around to the beginning. It also doesn't do anything interesting with your menu selection. You may want to break
out when the user picks an actual menu item.
The interesting parts are refilling the CURRNUMS array based on the starting and ending indices and including an extra "next" item in the select
loop.
ALLNUMBERS=({30..90})
start=0
howmany=25
while :
do
end=$((start + howmany - 1))
CURRNUMS=
for (( i = start; i < end ; i++ ))
do
cindex=$((i - start))
CURRNUMS[$cindex]=${ALLNUMBERS[$i]}
done
echo Presenting a new set of menu items...
select number in ${CURRNUMS[*]} next; do
echo You picked $REPLY
echo number is now: $number
if [ $REPLY = "next" ] || [ $REPLY = $howmany ] ; then
start=$end
break;
fi
done
done
Here's sample output:
Presenting a new set of menu items...
1) 30 5) 34 9) 38 13) 42 17) 46 21) 50 25) next
2) 31 6) 35 10) 39 14) 43 18) 47 22) 51
3) 32 7) 36 11) 40 15) 44 19) 48 23) 52
4) 33 8) 37 12) 41 16) 45 20) 49 24) 53
#? 2
You picked 2
number is now: 31
#? 25
You picked 25
number is now: next
Presenting a new set of menu items...
1) 54 5) 58 9) 62 13) 66 17) 70 21) 74 25) next
2) 55 6) 59 10) 63 14) 67 18) 71 22) 75
3) 56 7) 60 11) 64 15) 68 19) 72 23) 76
4) 57 8) 61 12) 65 16) 69 20) 73 24) 77
#? 3
You picked 3
number is now: 56
#? next
You picked next
number is now:
Presenting a new set of menu items...
1) 78 3) 80 5) 82 7) 84 9) 86 11) 88 13) 90
2) 79 4) 81 6) 83 8) 85 10) 87 12) 89 14) next
#? ^C