Find the answer to your Linux question:
Results 1 to 5 of 5
I would like to create a menu. It would consist of, choices 1-10 with specific commands associated. So what I am thinking, is I need to have a menu with ...
  1. #1
    Just Joined!
    Join Date
    May 2006
    Posts
    47

    How could I create a bash menu script?

    I would like to create a menu. It would consist of,

    choices 1-10 with specific commands associated. So what I am thinking, is I need to have a menu with 1 thru 10 multiple choice and then commands like

    read x

    If x=1 Then
    ssh A
    else if
    x=2 Then
    ssh B
    else if

    I know thats not neccisarilly the right way. My question is if anyone could help with some input on the best way to do this? How do I create the menu, is it one long echo command? Is If then the best way and what is the correct syntax?

    One last question, is there a way to automate in a script suing to another user, for instance I know you can put su user but unless you are root it asks for a password, is there way to automate the entry of the password?

  2. #2
    Linux Newbie birdman's Avatar
    Join Date
    Mar 2006
    Location
    Ireland
    Posts
    141
    You could use the case command instead of the many if else constructs.

    Use an echo, the format of which should be carried over from the script.

  3. #3
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,116
    Hi.

    Another method is to use select, noted in the tutorial:
    The select construct, adopted from the Korn Shell, is yet another tool for building menus.

    Example 10-29. Creating menus using select

    http://www.tldp.org/LDP/abs/html/testbranch.html
    Best wishes on your learning ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  4. #4
    Just Joined!
    Join Date
    Jan 2011
    Posts
    10
    Thanks guys for the quick responce
    Im going to atempt it tonight. Would it be fine if i post the script that i have created once done and you could tell me if its good to go

  5. #5
    oz
    oz is online now
    forum.guy
    Join Date
    May 2004
    Location
    arch linux
    Posts
    18,090
    Quote Originally Posted by Rustyhamster View Post
    Thanks guys for the quick responce
    Im going to atempt it tonight. Would it be fine if i post the script that i have created once done and you could tell me if its good to go
    Hello

    This thread is going on 5 years old, so locking it down. Feel free to carry on with any discussion about this topic in your own thread.

    Thanks.
    oz

    new members/users: read this first | new member faq
    no private messages requesting computer support - post them on the forums!
    please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.

Posting Permissions

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