A nice menu

Source: Internet
Author: User
Article Title: A good idea menu. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Code:
# Program: mmenu-shell script of user menu items
# Description:
# Program consisting of a series of functions providing user menus
# For simple tasks.
#
# Functions are loaded into memory and available for execution. Once
# Loaded, the main menu will be invoked. The main menu (entry point) is: MainMenu.
#
# The following functions are declared:
# MainMenu
# EditFile
# MailMenu
# UserUtilMenu
# FileDirUtilMenu
# GetFileName
# ExecuteCommand
#
# Last updated on 10/10/2002 by A.M. Foster
  
#*************************************** * ********************** 8
  
# Screen Display Variables
REV = 'tput rev'
OREV = 'tput sgr0'
BLD = 'tput smso'
OBLD = 'tput rmso'
  
# Various variables
MenuMsg = ""
MenuChoice = ""
  
#*************************************** * ****************************** 8
# Routine: MainMenu
# Main Menu function which displays the main menu to stdout.
  
MainMenu ()
{
  
# Menu loop
  
While true
Do
Tput clear
MenuChoice = ""
  
# Main Menu-display the main menu
  
Echo ""
Echo ""
Echo "$ {REV} Main Menu $ {OREV }"
Echo ""
Echo ""
Echo "1. $ {BLD} E $ {OBLD} dit/File"
Echo ""
Echo "2. $ {BLD} S $ {OBLD} end/Receive Mail ..."
Echo ""
Echo "3. $ {BLD} U $ {OBLD} ser Utilities ..."
Echo ""
Echo "4. $ {BLD} F $ {OBLD} ile Directory Utilities ..."
Echo ""
Echo "0. $ {BLD} L $ {OBLD} og Off System"
Echo ""
Echo ""
Echo "$ {BLD }$ {MenuMsg }$ {OBLD }"
Echo ""
Echo ""
Echo-n "$ {BLD} Select :$ {OBLD }"
MenuMsg = ""
  
# Get user's choice and evaluate with case statement
Read MenuChoice # get user selection
  
Case $ {MenuChoice} in
  
"1" | "e" | "E ")
EditFile
;;
  
"2" | "s" | "S ")
MailMenu
;;
  
"3" | "u" | "U ")
UserUtilMenu
;;
  
"4" | "f" | "F ")
FileDirUtilMenu
;;
  
"0" | "l" | "L ")
Echo ""
Echo ""
Echo "Exiting per User request! "
Sleep 2
Tput clear
Exit 1
;;
  
*)
MenuChoice = ""
MenuMsg = "$ {BLD} Invalid choice. Please try again. $ {OBLD }"
;;
  
# Example of menu command that is hidden from users. Note that
# It is not in the menu, but has a choice in the case statement.
       
"Admin ")
ExecuteCommand 'ps-ef | more'
;;
        
Esac # end of case statement
Done # end of menu loop
}
  
#*************************************** **************************************** *****
  
  
# Routine EditFile
# Presents the Edit File Menu to stdout
  
EditFile ()
{
MenuMsg = ""
While true
Do
MenuChoice = ""
Tput clear
  
Echo ""
Echo ""
Echo "$ {REV} edit file $ {OREV }"
Echo ""
Echo ""
Echo "1. $ {BLD} E $ {OBLD} nter File Name"
Echo ""
Echo "2. Enter File Name from Li $ {BLD} s $ {OBLD} t ..."
Echo ""
Echo "0. $ {BLD} M $ {OBLD} ain Menu"
Echo ""
Echo ""
Echo "$ {BLD }$ {MenuMsg }$ {OBLD }"
Echo ""
Echo ""
Echo-n "$ {BLD} Select :$ {OBLD }"
MenuMsg = ""
  
# Get user's choice and evaluate with case statement
Read MenuChoice # get user selection
  
Case $ {MenuChoice} in
"1" | "e" | "E ")
Echo-n "Enter file name to edit :"
Read FileName
If [-z "$ {FileName}"] # check if user provided a file name
Then
MenuMsg = "You did not enter a valid file name! "
Else
If [-f $ {FileName}] # check if file exists
Then
# Check if file is a text file
If ["file $ {FileName} | grep text>/dev/null"]
Then
Filesoktoedit = "y"
Else
MenuMsg = "$ {FileName}-is not an editable file! "
Fi
Else
Filesoktoedit = "y"
Fi
Fi
  
If [$} filesoktoedit} = "y"]
Then
Vi "$ {FileName }"
Echo ""
Echo "Press any key to continue .."
Fi
;;
  
"2" | "s" | "S ")
FileName = ""
GetFileName FileName
  
If [$? -Eq 0]
Then
If ["file $ {FileName} | grep text>/dev/null"]
Then
Vi "$ {FileName }"
Echo ""
Echo "Press any key to continue .."
Else
MenuMsg = "$ {BLD }$ {FileName}-is not an editable file! $ {OBLD} 1"
Fi
Fi
;;
  
"0" | "m" | "M ")
Break
;;
  
*)
MenuChoice = ""
MenuMsg = "$ {BLD} Invalid Choice! Please try again. $ {OBLD }"
;;
Esac
Done
Return 0
} # End of EditFile function
  
  
#*************************************** **************************************** ***
  
# Routine MailMenu
# Displays Mail Menu to stdout
  
MailMenu ()
{
MessageMenu = ""
While true
Do
Tput clear
MenuChoice = ""
Echo ""
Echo ""
Echo "$ {REV} mail menu $ {OREV }"
Echo ""
Echo ""
Echo "1. $ {BLD} S $ {OBLD} end Mail"
Echo ""
Echo "2. $ {BLD} R$ {OBLD} eceive Mail"
Echo ""
Echo "0. $ {BLD} M $ {OBLD} ain Menu"
Echo ""
Echo "$ {BLD }$ {MenuMsg }$ {OBLD }"
Echo ""
Echo ""
Echo-n "$ {BLD} Select :$ {OBLD }"
MenuMsg = ""
  
# Get user's choice and evaluate with case statement
Read MenuChoice # get user selection
  
Case $ {MenuChoice} in
"1" | "s" | "S ")
Echo ""
Echo-n "Enter a mail ID to send :"
Read mailid
  
If [-z "$ {mailid}"]
Then
MenuMsg = "You mus

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.