I\'m prompting questions in a bash script like this:
optionsAudits=(\"Yep\" \"Nope\")
echo \"Include audits?\"
select opt in \"${optionsAudits[@]}\"; do
Your problem is due to the fact that select
will ignore empty input. For your case, read
will be more suitable, but you will lose the utility select
provides for automated menu creation.
To emulate the behaviour of select
, you could do something like that :
#!/bin/bash
optionsAudits=("Yep" "Nope")
while : #infinite loop. be sure to break out of it when a valid choice is made
do
i=1
echo "Include Audits?"
#we recreate manually the menu here
for o in "${optionsAudits[@]}"; do
echo "$i) $o"
let i++
done
read reply
#the user can either type the option number or copy the option text
case $reply in
"1"|"${optionsAudits[0]}") includeAudits=true; break;;
"2"|"${optionsAudits[1]}") includeAudits=false; break;;
"") echo "empty"; break;;
*) echo "Invalid choice. Please choose an existing option number.";;
esac
done
echo "choice : \"$reply\""