Many years ago Kevin Clark wrote a nice little menu generator for SCO systems. I've used this for years (Kevin and I were once partners in Lawrence and Clark, Inc.) and have always liked the simplicity of its design.

(Note: Kevin lost the source code for this. See Perl Kcmenu if you need this for something other than SCO Unix.)

Here's a simple menu:

# Comments: this is a menu

$$My Menu

$L$Run "ls"$ls -l | more
$M$Read Mail$mail


If this is saved as "mymenu", then "kcmenu mymenu" will display a nice little boxed menu that probably works just as you expect it would.

Most of what you need to understand about kcmenu is explained in the sample menu included with the distribution and reproduced here:

#     Kevin Clark's Menu System - kcm
#     (c) 1990-92 Kevin Clark
#     sample menu for kcm use
#     syntax is:
#     #                      for remark
#     blank line             print a blank line
#     first char             token delimiter (!%^@~,`+=_*&$)
#     first token  (max=6)   short description - press 1st character
#     second token           full description - centered if no 1st token
#     third token            bourne shell function or *exit* macro
#     kcm looks first in /usr/kctools or the directory pointed to
#     by environment variable KCMENUS then it looks in the current
#     directory for the menu file
#     to always use present directory:
#     KCMENUS=. ; export KCMENUS
#     execute with kcm sample.kcm

$$KCM Menu System
$$Version 3.1
$$Copyright (c) 1990-92 by Kevin Clark

%%This is a sample menu for the KCM Menu System.
||Use this as an example for designing your own menus

!LIST!List files in current directory!l | more -w
!COPY!Copy XENIX floppy disk!diskcp 
# remark lines do not add space to the menu
# Any delimiter is allowed:
_DOS_List files on DOS floppy_dosdir A: | more -w
~FORMAT~Format floppy disk for XENIX~format /dev/rfd096ds15 
&TAR&Copy present directory to floppy&tar cv2 . 

%QUIT%Quit Menu Program%*exit*

!!** Thank you for using our product **

Note that ANY delimiter is valid for separating menu descriptions from actions, and that each new line can have its own delimiter. The only special action is "*exit*", which exits the current menu.

You can nest menus by simply calling "kcmenu" with the name of another menu, and since the menus themselves are simply text files, you can build them "on the fly"; the following is a shell script that builds a menu that contains a list of files to be copied elswhere:

export menu
exec 1> $menu
echo ""
echo "!!Please choose:"
echo ""
for i in `ls -d [a-z]*`
echo "!$x!$i!cp $i /somewhere"
if [ $x -gt "15" ]
echo " "
echo "!Q!Quit!*exit*"
exit 0
kcmenu /tmp/m$$

Obviously this is a simplistic example, but you can build fairly complex programs using this sort of technique.

Got something to add? Send me email.

(OLDER) <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> KCMENU- Unix Menu Program

Increase ad revenue 50-250% with Ezoic

More Articles by

Find me on Google+

© Tony Lawrence

Kerio Samepage

Have you tried Searching this site?

Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

privacy policy