Find the answer to your Linux question:
Results 1 to 3 of 3
Hi all, Trying to build a series of options in a bash script and im fine with 1 menu but i want to put a sub menu in one of ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2012
    Posts
    6

    submenus in bash


    Hi all,

    Trying to build a series of options in a bash script and im fine with 1 menu but i want to put a sub menu in one of the options...

    #!/bin/bash
    menu ()
    {
    clear
    echo "-------------------------------"
    echo " M A I N - M E N U"
    echo " 1) option "
    echo " 2) option "
    echo " 3) option "
    echo " 4) option "
    echo "-------------------------------"
    while
    do
    read action
    case $action in
    "1")
    do something
    ;;
    "2")
    do something else
    ;;
    "3")
    submenu ()
    {
    clear
    echo "-------------------------------"
    echo "SUB -MENU"
    echo "a) option"
    echo "b) option"
    echo "-------------------------------"
    while :
    do
    read subaction
    case $subaction in
    "a")
    do something ;;
    "b")
    do something else ;;
    esac
    done
    }
    submenu;
    ;;
    "4")
    echo "Bye!"
    exit 0
    ;;
    *)
    echo "Error: Invalid option..."
    read -p "Press [Enter] key to continue..." readEnterKey
    ;;
    esac
    done
    }
    menu;


    but bash is complaining that there's a syntax error, can someone tell me how can i create in submenus in bash ?

    thanks,

  2. #2
    Just Joined!
    Join Date
    Dec 2012
    Posts
    6
    Solved it

    Hadnt added a ;; what i wrote is actually correct. Can see why its called bash...

    solution:

    3)
    submenu ()
    {
    clear
    echo "-------------------------------"
    echo "SUB -MENU"
    echo "a) option"
    echo "b) option"
    echo "-------------------------------"
    while :
    do
    read subaction
    case $subaction in
    "a")
    do something ;;
    "b")
    do something else ;;
    esac
    done
    }
    submenu;
    ;;
    4)

  3. #3
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    211
    hi,

    bash is complaining that there's a syntax error
    «there's a tree in a forrest.» let me guess, it's made of wood! XD

    what's the error message? exactly.

    functions don't have to be nested because they are called inside another.

    don't you have something to test in the first `while'?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •