Qba
Qba

Reputation: 5

Select nested statements

I wrote something like this

    #!/bin/bash
PS3='Select an option and press Enter: '
select tree_1 in Date Host Users Quit
do
    case $tree_1 in
        Date)
            select tree_1_1 in Date1 Date2
            do
                case $tree_1_1 in
                    Date1) date;;
                    Date2) date;;
            esac
    done
        Host)  hostname;;
        Users)  who;;
        Quit)  break;;
    esac
done

and after execute I have

./1menu: line 14: syntax error near unexpected token `)'

./1menu: line 14: ` Host) hostname;;'

Can you tell me where the problem is? Thank for help.

Upvotes: 0

Views: 393

Answers (1)

pb2q
pb2q

Reputation: 59617

You haven't terminated your Date case. You need to add ;; after the inner case statement:

Date)
    select tree_1_1 in Date1 Date2
    do
        case $tree_1_1 in
            Date1) date;;
            Date2) date;;
        esac
    done
    ;;   # you're missing this terminator

Upvotes: 3

Related Questions