我有一个从数组创建菜单的脚本。现在,我可以从数组中选择所有8个值。我只允许同时选择两个。我该怎么办?
function db_select {
clear
echo "">$DB_SELECTION
GENERIC_OPTIONS="Q W E R T Y U I"
for DBS in $GENERIC_OPTIONS;
do
options=("${options[@]}" "$DBS")
done
menu() {
echo "Avaliable options:"
for i in ${!options[@]}; do
printf "\033[32m%3d%s)\033[0m. %s\n" $((i+1)) "${choices[i]:- }" "${options[i]}"
done
[[ "$db_list" ]] && echo "$db_list"; :
}
prompt="Check an option (again to uncheck, ENTER when done): "
while menu && read -rp "$prompt" num && [[ "$num" ]]; do
[[ "$num" != *[![:digit:]]* ]] &&
(( num > 0 && num <= ${#options[@]} )) ||
{ db_list="Invalid option: $num"; continue; }
((num--)); #db_list="${options[num]} ${choices[num]:+un}checked"
[[ "${choices[num]}" ]] && choices[num]="" || choices[num]="+"
done
printf "You selected:"; msg=" nothing"
for i in ${!options[@]}; do
[[ "${choices[i]}" ]] && { printf " %s" "${options[i]}"; msg=""; } && printf "%s\n" "${options[i]}" >> $DB_SELECTION && db_download_remote "${options[i]}"
done
echo "$msg"
}