Tuesday, June 18, 2024
HomeUNIX shellKorn shellCreating a Kornshell Script with Text-Based Menus in VI

Creating a Kornshell Script with Text-Based Menus in VI

This tech-recipe contains basic information on how to create text- based menus for kornshell scripts in VI. My experience is with IBM AIX 4.x.

To begin, create a new file (for example, test.ksh) by typing the following: vi test.ksh

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

In this file, we will add the following lines (An explanation is given below.):

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

“Edit script”)
vi test.ksh;;

“Print Report”)
lp test.ksh;;

“Exit”) break ;;


When run, the lines above will look like the following:

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

This is a basic menu-driven script.


PS3= :
This is what will be shown at the bottom. I usually have the name of the script. (in my example, Test Menu, enter choice:)

select case_menu … :
This can be whatever you choose it to be. Be sure you reference the same name in the: case $clean_menu in

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

Always close each command with the following: ;; (Notice you need 2.)

In the beginning, start with a 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, You could even have your script call functions you create within the script.

Jimmy S
Jimmy Shttp://blogs.tech-recipes.com/jimmyselix
Jimmy Selix is an early adopter that loves to be one of the first on the block to have the latest and greatest in technology and gadgets. Another love of his is being able to share his knowledge to others seeking it. Feel free to drop any comments or questions that you may have.


Please enter your comment!
Please enter your name here

Most Popular


Recent Comments

error: Content is protected !!