Creating a kornshell script with text-based menus in VI

Home -> UNIX -> Shells -> ksh

10623 views

From the computer of: seamonkey420 (132 recipes)
Created: Aug 13, 2004


Add a comment

Add to:
Add to stumbleuponAdd to del.icio.usDigg itAdd to FURL

This recipe give a quick run-through on how to create text based menus for ksh scripts in VI. My experience is with IBM AIX 4.x. This a very, very basic recipe.

Create a new file (for example, test.ksh)
by typing: vi test.ksh

the file test.ksh will be created and opened in VI.

in this file, we will add the following lines (i will explain each below)
________

clear
print "TEST Script MENU"
PS3="Test Menu, enter choice:"
select clean_menu in "View script" "Edit script" "Print script" "Exit"
do
case $clean_menu in
"View script")
pg test.ksh;;

"Edit script")
vi test.ksh;;

"Print Report")
lp test.ksh;;

"Exit") break ;;
esac
done

_____

This will look like this when ran!

TEST Script MENU
1) View script
2) Edit script
3) Print script
4) Exit
Test Menu, enter choice:


this a super basic menu driven script.

_____


PS3= : what will show at the bottom, usually i have the name of the script (in my example, Test Menu, enter choice:)

select case_menu ... : can be whatever you choose to be, just be sure you reference the same name in the: case $clean_menu in

The options after the select case_menu : they are the menu options that will show up. You need to have these match up with the references to them in the latter part of the script.

Always close each command with: ;; (you need 2!)

Best advice is to start with a very simple script and learn how that works. Then once you get the basics, you can start creating submenus, or have menu options that will call other scripts or menus or even have your script call functions you create with in the script.

Subscribe to the Tech-Recipes Newsletter

You can get tips like this delivered in your email every week!

Enter your Email

We will never, ever sell your email address or spam you.





Related recipes:

  Reading a list of data into a function using a script.
  Set an environment variable in Korn shell (ksh)
  Checking if a variable is a number in ksh
  appending a list of files to one file using xargs command
  Some Common AIX/Unix Commands
  Enable vi ksh command line editing

 

Sponsored links

 

Login

Nickname

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.