Here is a way to do this with an array.
#!/bin/bash questions=( "How to see apache config file" "Command for listing processes" "My hovercraft is full of eels" ) for((q=0; q<${#questions[@]}; q++)); do echo "Execute question $q?" select result in Yes No; do case $result in Yes) echo "${questions[q]}";; esac break done done
Using select for this seems rather clumsy, though. Perhaps just replace it with
read -p "Execute question $q? " -r result case $result in [Yy]*) echo "${questions[q]}";; esac
Having just a list of questions still seems weird. With Bash 5+ you could have an associative array, or you could have a parallel array with the same indices with answers to the questions. But keeping each question and answer pair together in the source would make the most sense. Maybe loop over questions and answers and assign every other one to an answers array, and only increment the index when you have read a pair?
pairs=( "How to see Apache config file" "cat /etc/httpd.conf" "Command for listing processes" "ps" "My hovercraft is full of what?" "eels" ) questions=() answers=() for((i=0; i<=${#pairs[@]}/2; ++i)); do questions+=("${pairs[i*2]}") answers+=("${pairs[1+i*2]}") done
This ends up with two copies of everything, so if you are really strapped for memory, maybe refactor to just a for loop over the strings and get rid of the pairs array which is only useful during initialization.