Naming menu options

Issue

I’m looking to name my menu options, it currently looks like this –

1) Option 1
2) Option 2
3) Option 3
4) Quit

I tried adding menu descriptions by editing the following but it returns no results when you enter a menu number

options=("Option 1 - Search with no date filter. SLOW!!" "Option 2 - Search via year" "Option 3 - Full date search" "Quit")

I would like it to look like this –

1) Option 1 - Search with no date filter. SLOW!!
2) Option 2 - Search via year
3) Option 3 - Full date search
4) Quit

Full script –

#!/bin/bash
echo ""
PS3='Please enter your choice: '
echo ""
#options=("Option 1 - Search with no date filter. SLOW!!" "Option 2 - Search via year" "Option 3 - Full date search" "Quit")
options=("Option 1" "Option 2" "Option 3" "Quit")
echo ""
select opt in "${options[@]}"
do
    case $opt in
        "Option 1")
            echo "" 
            echo Please enter the telephone number?
            echo ""
            read vartel
            echo ""
            grep -e $vartel /root/hourly/cdr_export-hourly-*.csv
            echo ""
            ;;
        "Option 2")
            echo "" 
            echo Please enter the telephone number?
            echo ""
            read vartel
            echo ""
            echo Please enter the last two year digits?
            echo ""
            read varyear
            echo ""
            grep -e $vartel /root/hourly/cdr_export-hourly-$varyear*.csv
            echo ""
            ;;
        "Option 3")
            echo "" 
            echo Please enter the telephone number?
            echo ""
            read vartel
            echo ""
            echo Please enter the last two year digits?
            echo ""
            read varyear
            echo ""
            echo Please enter the month?
            echo ""
            read varmonth
            echo ""
            echo Please enter the day?
            echo ""
            read varday
            echo ""
            grep -e $vartel /root/hourly/cdr_export-hourly-$varyear-$varmonth-$varday*.csv
            echo ""
            ;;
        "Quit")
            break
            ;;
        *) echo "invalid option $REPLY";;
    esac
done

Solution

How about:

case "$opt" in
  "Option 1"*)
    ...
    ;;
  "Option 2"*)
    ...
    ;;
  "Quit")
    break
    ;;
  *)
    ...
    ;;
esac

Answered By – Bach Lien

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published