In addition to Aserre's helpful answer , which explains the problem with your code and offers an effective workaround, with reference information and a universal, reusable custom selectimplementation that allows empty input :
Background Information
: select ( Enter) - .
, select , , .
, - $opt, int this case - select, , .
- 'Yep', 'Nope' - , , .
( , $REPLY , , , , ).
, , ,
^C (Ctrl+C), .
select,
, select, ( Enter). , , :
selectWithDefault() {
local item i=0 numItems=$#
for item; do
printf '%s\n' "$((++i))) $item"
done >&2
while :; do
printf %s "${PS3-#? }" >&2
read -r index
[[ -z $index ]] && break
(( index >= 1 && index <= numItems )) 2>/dev/null || { echo "Invalid selection. Please try again." >&2; continue; }
break
done
[[ -n $index ]] && printf %s "${@: index:1}"
}
:
echo "Include audits (default is 'Nope')?"
optionsAudits=('Yep' 'Nope')
opt=$(selectWithDefault "${optionsAudits[@]}")
case $opt in
'Yep') includeAudits=true; ;;
''|'Nope') includeAudits=false; ;;
esac
:
. , select; , , :
optionsAudits=("Yep" "Nope")
echo "Include audits (^C to abort)?"
select opt in "${optionsAudits[@]}"; do
[[ -n $opt ]] || { echo "What that? Please try again." >&2; continue; }
break
done
case $opt in
'Yep')
includeAudits=true
;;
'Nope')
includeAudits=false
;;
esac
: