LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-11-2009, 10:41 AM   #1
BobTruck
LQ Newbie
 
Registered: Jul 2009
Distribution: Slackware
Posts: 5

Rep: Reputation: 0
I need help with a CLI menu shell script


I am trying to write a shell script that displays a menu with 22 options of commands. I would like to have an option to display another menu of more options, but I can't get it to function properly. I am using a while loop with case for the options. Any help would be greatly appreciated.

Code:
#!/sbin/sh

DisplayMenuA()
{
  echo ""
  echo ""
  echo "================================================================================"
  echo "================================= All Scripts =================================="
  echo "================================================================================"
  echo ""
  echo " 1)  checkchALL"
  echo " 2)  checkchMTNS"
  echo " 3)  checkchNOCO"
  echo " 4)  checkchSOCO"
  echo " 5)  checksenders"
  echo " 6)  ckSenseData"
  echo " 7)  ckITR"
  echo " 8)  ckfailedspot"
  echo " 9)  ckproclaim"
  echo " 10) cksender"
  echo " 11) cktonelevel"
  echo " 12) cktones"
  echo " 13) hecheckall"
  echo " 14) heckallARCHIVE"
  echo " 15) heckallerr"
  echo " 16) heckallnofail"
  echo " 17) heckerr"
  echo " 18) iptonecheck"
  echo " 19) spotck"
  echo " 20) hecknofail"
  echo " 21) hecheck"  
  echo " 22) checkdate"
  echo " q)  Quit"
  echo ""
}

DisplayMenuB()
{
  echo ""
  echo ""
  echo "================================================================================"
  echo "=============================== All Scripts (cont.) ============================"
  echo "================================================================================"
  echo ""
  echo " 23) checkscheds"
  echo " 24) cklevels"
  echo " 25) spottilde"
  echo " 26) check"
  echo " 27) cktones_tail"
  echo " 28) cklevels_tail"
  echo " 29) cklevels2_tail"
  echo " 30) check_sch"
  echo " 31) chcheck"
  echo " 32) search_log"
  echo " 33) ch_log"
  echo " 34) tailerr"
  echo " 35) ck_corrupt_proclaim"
  echo " 36) checkALL_NIC"
  echo " 37) checkchannel"
  echo " 38) checkARCHIVE"
  echo " 39) ckARCHIVEadxxx"
  echo " 40) checkchannelALL"
  echo " 41) checknetlv"
  echo " 42) cknetlevels_tail"
  echo " 43) checknetlevel"
  echo " 44) spotckss"
  echo " q)  Quit"
  echo ""
}

DisplayMenuC()
{
  echo ""
  echo ""
  echo "================================================================================"
  echo "=============================== All Scripts (cont.) ============================"
  echo "================================================================================"
  echo ""
  echo " 45) check_zdig"
  echo " 46) copyfilestohe"
  echo " 47) count"
  echo " 48) count_list"
  echo " 49) countverifs"
  echo " 50) countverifs_list"
  echo " 51) gettones"
  echo " 52) pulltones"
  echo " 53) checkchlevels"
  echo " 54) search.ss"
  echo " 55) search.all"
  echo " 56) chartlevels"
  echo " 57) chartlevels.gbl "
  echo " 58) chartlevels.sh "
  echo " 59) chartlevelsnow"
  echo " 60) checkch"
  echo " 61) checkchlevel"
  echo " 62) checklevels"
  echo " 63) checklog"
  echo " 64) checklv"
  echo " 65) checkraid"
  echo " 66) checksched"
  echo " q)  Quit"
  echo ""
}

Wait()
{
  echo ""
  echo "Press <Enter> to continue. \c"
  read bogus
}

#
# beginning of main program
#

option="start"
while [ "$option" != "q" -a "$option" != "quit" ]
do
  clear
  DisplayMenuA
  echo "Enter option (n for next \ l for last): \c"
  read option

  while [ "$option = "n" -a "$option" = "N" ]
  do
    clear
    DisplayMenuB
    echo "Enter option (l for last or <Enter> for main): \c"
    read option
  done
  
    while [ "$option" = "l" -a "$option" = "L" ]
    do
      clear
      DisplayMenuC
      echo "Enter option or <Enter> for main: \c"
      read option
    done
	
  case $option in

    1)
      checkchALL
      ;;

    2)
      checkchMTNS
      ;;

    3)
      checkchNOCO
      ;;

    4)
      checkchSOCO
      ;;

    5)
      checksenders
      ;;

    6)
      ckSenseData
      ;;

    7)
      ckITR
      ;;

    8)
      ckfailedspot
      ;;
	  
    9)
      ckproclaim
      ;;
	  
    10)
      cksender
      ;;
	 
    11)
      cktonelevel
      ;;
	  
    12)
      cktones
      ;;
	  
    13)
      hecheckall
      ;;
	  
    14)
      heckallARCHIVE  
      ;;
	  
    15)
      heckallerr
      ;;
	  
    16)
      heckallnofail
      ;;
	  
    17)
      heckerr
      ;;
	  
    18)
      iptonecheck
      ;;
	  
    19)
      spotck
      ;;
	  
    20)
      hecknofail
      ;;
	  
    21)
      hecheck
      ;;
	  
    22)
      checkdate
      ;;
	  
    23)
      checkscheds
      ;;
	  
    24)
      cklevels
      ;;
	  
    25)
      spottilde
      ;;
	  
    26)
      check
      ;;
	  
    27)
      cktones_tail
      ;;
	  
    28)
      cklevels_tail
      ;;
	  
    29)
      cklevels2_tail
      ;;
	  
    30)
      check_sch
      ;;
	  
    31)
      chcheck
      ;;
	  
    32)
      search_log
      ;;
	  
    33)
      ch_log
      ;;
	  
    34)
      tailerr
      ;;
	  
    35)
      ck_corrupt_proclaim
      ;;
	  
    36)
      checkALL_NIC  
      ;;
	  
    37)
      checkchannel
      ;;
	  
    38)
      checkARCHIVE
      ;;
	
    39)
      ckARCHIVEadxxx
      ;;
	  
    40)
      checkchannelALL
      ;;
	  
    41)
      checknetlv
      ;;
	  
    42)
      cknetlevels_tail
      ;;
	  
    43)
      checknetlevel
      ;;
	  
    44)
      spotckss
      ;;
	  
    45)
      check_zdig
      ;;
	  
    46)
      copyfilestohe
      ;;
	  
    47)
      count
      ;;
	  
    48)
      count_list
      ;;
	  
    49)
      countverifs
      ;;
	  
    50)
      countverifs_list
      ;;
	  
    51)
      gettones
      ;;
  
    52)
      pulltones
      ;;
	  
    53)
      checkchlevels
      ;;
	  
    54)
      search.ss
      ;;
	  
    55)
      search.all
      ;;
	  
    56)
      chartlevels
      ;;
	  
    57)
      chartlevels.gbl
      ;;
	  
    58)
      chartlevels.sh
      ;;
	  
    59)
      chartlevelsnow
      ;;
	  
    60)
      checkch
      ;;
	  
    61)
      checkchlevel
      ;;
	  
    62)
      checklevels
      ;;
	  
    63)
      checklog
      ;;
	  
    64)
      checklv
      ;;
	  
    65)
      checkraid
      ;;
	  
    66)
      checksched
      ;;
	  
    "m"|"M")
	  
      ;;
	  
    "l"|"L")
	  
      ;;
	  
    "quit"|"q")
      ;;
   
    *)
      echo "ERROR: Command not recognized."
      ;;

  esac

  if [ "$option" = "n" -a "$option" = "N" ]
    then
      clear
      DisplayMenuB
      echo "Enter option ( l for last ): \c"
      read option
    else
      if [ "$option" = "l" -a "$option" = "L" ]      
        then
          clear
          DisplayMenuC
          echo "Enter option or <Enter>: \c"
          read option
      else
        if [ "$option" != "q" -a "$option" != "quit" ]
          then
	      Wait 
        fi
      fi
  fi

done
 
Old 11-11-2009, 04:10 PM   #2
lewc
Member
 
Registered: Nov 2009
Distribution: Gentoo, Slackware or Debian
Posts: 60
Blog Entries: 1

Rep: Reputation: 18
content removed

Last edited by lewc; 11-27-2009 at 03:41 PM.
 
Old 11-12-2009, 10:32 AM   #3
BobTruck
LQ Newbie
 
Registered: Jul 2009
Distribution: Slackware
Posts: 5

Original Poster
Rep: Reputation: 0
There is not an error, just a lack of function. I would like to display the first menu, then if selected the second and then the third. I have been able to display the first, but then I am only able to go the second or third from the first. If I try to go to the third menu from the second menu, it goes to the Wait() and then returns to the first menu. I hope this helps clarify my issue.
 
Old 11-12-2009, 05:57 PM   #4
lewc
Member
 
Registered: Nov 2009
Distribution: Gentoo, Slackware or Debian
Posts: 60
Blog Entries: 1

Rep: Reputation: 18
content removed

Last edited by lewc; 11-27-2009 at 03:40 PM.
 
Old 11-14-2009, 10:33 AM   #5
BobTruck
LQ Newbie
 
Registered: Jul 2009
Distribution: Slackware
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks lewc, I will do a rewrite and give it a try.
 
Old 11-14-2009, 10:40 AM   #6
lwasserm
Member
 
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184

Rep: Reputation: 41
bash has a builtin command "select" which you may find useful instead of coding it up yourself. From man bash or "help select"
Code:
$ help select
select: select NAME [in WORDS ... ;] do COMMANDS; done
    The WORDS are expanded, generating a list of words.  The
    set of expanded words is printed on the standard error, each
    preceded by a number.  If `in WORDS' is not present, `in "$@"'
    is assumed.  The PS3 prompt is then displayed and a line read
    from the standard input.  If the line consists of the number
    corresponding to one of the displayed words, then NAME is set
    to that word.  If the line is empty, WORDS and the prompt are
    redisplayed.  If EOF is read, the command completes.  Any other
    value read causes NAME to be set to null.  The line read is saved
    in the variable REPLY.  COMMANDS are executed after each selection
    until a break command is executed.
 
Old 11-14-2009, 03:06 PM   #7
lewc
Member
 
Registered: Nov 2009
Distribution: Gentoo, Slackware or Debian
Posts: 60
Blog Entries: 1

Rep: Reputation: 18
content removed

Last edited by lewc; 11-27-2009 at 03:40 PM.
 
Old 11-17-2009, 06:29 PM   #8
BobTruck
LQ Newbie
 
Registered: Jul 2009
Distribution: Slackware
Posts: 5

Original Poster
Rep: Reputation: 0
lewc, I started the rewrite but my coworkers thought that a multilevel menu was not simple enough. I ended up rewriting the menu to display 3 rows with all of the options for the user. I appreciate the information and advise you gave me and I will use it in my scripts at home. I guess that sometimes simple is better (for the end user). Thanks also to lwasserm for the post about using select.
 
Old 11-17-2009, 06:41 PM   #9
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
You might also consider using the "dialog" program to generate nice, colored ncurses menus.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Menu bashed shell script for users shell 0.o Linux - Server 6 02-14-2013 06:00 AM
How to add e menu entry to KDE start menu over CLI browny_amiga Linux - General 7 02-08-2009 03:05 PM
I can execute shell script from CLI but failed to do via cron UltraSoul Linux - Software 2 06-24-2008 10:10 PM
shell script menu marsIV Programming 1 10-09-2007 08:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration