APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

© December 1997 Tony Lawrence


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

Inexpensive and informative Apple related e-books:

Take Control of Apple Mail, Third Edition

Digital Sharing Crash Course

El Capitan: A Take Control Crash Course

Photos: A Take Control Crash Course

Sierra: A Take Control Crash Course

More Articles by © Tony Lawrence

Printer Friendly Version

Have you tried Searching this site?

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

Printer Friendly Version

The idea of "work, then get paid" has been deeply ingrained in our culture by employers who want to limit their risk. Well, I like to limit my risks also. I like to get paid before I do work. (Tony Lawrence)

Linux posts

Troubleshooting posts

This post tagged:


Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode