277 lines
6.3 KiB
Groff
277 lines
6.3 KiB
Groff
.TH menu "" "" "/rdb Command"
|
|
.PC "Root menu with some COHERENT commands"
|
|
.B menu
|
|
.PP
|
|
.II "command^menu"
|
|
The command
|
|
.B menu
|
|
displays a table of commands that you can execute by
|
|
simply typing a number or a name.
|
|
Menus are useful for inexperienced users.
|
|
Experienced users can set up a menu very easily.
|
|
.PP
|
|
.B menu
|
|
is a shell script that simply echos the
|
|
.B menu
|
|
table of choices, then waits for the user to type a number or name.
|
|
Then
|
|
.B menu
|
|
uses a shell \fBcase\fR statement
|
|
to execute a command or series of commands for each
|
|
choice.
|
|
To set up your own menus, simply copy the
|
|
.B menu
|
|
shell command from the
|
|
.B $RDB/bin
|
|
into your directory, then edit it.
|
|
You should change its name to
|
|
.B Menu
|
|
or
|
|
.BR Menu.something ,
|
|
to keep from confusing
|
|
.BR /rdb .
|
|
.PP
|
|
There is a sample local
|
|
.B menu,
|
|
named
|
|
.B Menu
|
|
in directory
|
|
.BR $RDB/demo .
|
|
.SH Example
|
|
The following gives an example menu:
|
|
.B1
|
|
COHERENT MENU
|
|
Number Name For
|
|
------- ------- ----------------------------------------------------
|
|
0 exit leave menu or return to higher menu
|
|
1 Menu goto another local menu (if any)
|
|
2 sh get COHERENT shell
|
|
3 vi edit a file
|
|
4 mail read mail
|
|
5 send send mail to someone
|
|
6 cal see your calendar
|
|
7 who see who is on the system
|
|
8 ls list the files in this directory
|
|
9 cat display a file on the screen
|
|
10 rdb display rdb commands
|
|
.sp \n(pDu
|
|
Enter a number or name for the action you wish or DEL to exit:
|
|
.B2
|
|
.PP
|
|
.B menu
|
|
waits for you to type your choice of number or name.
|
|
Numbers are quicker to type, but names are more easily remembered, and
|
|
help you learn how to do things at the shell level.
|
|
.SH "Setting Up Your Own Menus"
|
|
You can automate your operations with menus.
|
|
If you have naive users who might have trouble learning or
|
|
remembering the COHERENT or
|
|
.B /rdb
|
|
commands, you can set up menus for them.
|
|
Also, when you have an operation in which a few commands
|
|
are repeatedly executed, you can put them into a menu for simple choice.
|
|
.PP
|
|
You can put your menus in the directories in which they
|
|
will be used or in your
|
|
.B $HOME/bin
|
|
or other
|
|
.B bin
|
|
directory.
|
|
.PP
|
|
To start, go to the directory of your choice and copy the
|
|
.B $RDB
|
|
.B menu
|
|
to your directory:
|
|
.DM
|
|
cp $RDB/bin/menu Menu
|
|
.DE
|
|
.PP
|
|
or
|
|
.DM
|
|
cp $RDB/demo/Menu .
|
|
.DE
|
|
.PP
|
|
We suggest the convention of using the name
|
|
.B Menu
|
|
with the capital `M'
|
|
so it appears at the top of your list of files when you do an
|
|
.B lc
|
|
command.
|
|
.PP
|
|
You can then name submenus; for example,
|
|
\fBMenu.\fIother\fR
|
|
where
|
|
.I other
|
|
is something that suggests the kinds of commands the menu displays.
|
|
.PP
|
|
Now edit the
|
|
.B Menu
|
|
file.
|
|
As you study the code, you will find that it is very easy to
|
|
create your own directory.
|
|
.PP
|
|
Menu is in two parts.
|
|
The first part is the menu table:
|
|
.DM
|
|
cat << SCREEN
|
|
$CLEAR COHERENT MENU
|
|
Number Name For
|
|
------- ------- -------------------------
|
|
0 exit leave menu or return to higher menu
|
|
1 Menu goto another local menu (if any)
|
|
2 sh get unix shell
|
|
3 vi edit a file
|
|
4 mail read mail
|
|
5 send send mail to someone
|
|
6 cal see your calendar
|
|
7 who see who is on the system
|
|
8 ls list the files in this directory
|
|
9 cat display a file on the screen
|
|
10 rdb display rdb commands
|
|
.sp \n(pDu
|
|
Please enter a number or name for the action you wish or DEL to exit:
|
|
.sp \n(pDu
|
|
SCREEN
|
|
.DE
|
|
.PP
|
|
The command
|
|
.B cat
|
|
simply sends to the screen everything
|
|
after the command and before the line that
|
|
begins with
|
|
.BR SCREEN ,
|
|
including the line that begins
|
|
.BR "Please enter a number" .
|
|
.PP
|
|
The shell replaces
|
|
.B $CLEAR
|
|
on the first line with a sequence of characters that clears the terminal.
|
|
.B $CLEAR
|
|
must have been set by the following command in the
|
|
.B menu
|
|
or in the
|
|
.B .profile
|
|
file of the user:
|
|
.DM
|
|
.II clear
|
|
CLEAR=`clear`
|
|
.DE
|
|
.PP
|
|
The second part of
|
|
.B Menu
|
|
is a large
|
|
.B case
|
|
statement that you can edit to do what you want.
|
|
Here is a sample:
|
|
.DM
|
|
.II read
|
|
read ANSWER COMMENT
|
|
.DE
|
|
.DM
|
|
.II case
|
|
case $ANSWER in
|
|
.DE
|
|
.DM
|
|
0|exit) exit 0 ;;
|
|
1|Menu) Menu ;;
|
|
2|sh) sh ;;
|
|
3|vi)
|
|
echo 'Which file or files do you wish to edit'
|
|
read ANSWER COMMENT
|
|
vi $ANSWER $COMMENT
|
|
;;
|
|
.DE
|
|
.DM
|
|
4|mail) mail ;;
|
|
5|send)
|
|
echo 'Please enter login name of person to send mail to'
|
|
read ANSWER COMMENT
|
|
echo 'Type you letter, and end by typing Ctrl-d'
|
|
mail $ANSWER
|
|
;;
|
|
.DE
|
|
.DM
|
|
6|cal) (cd ; calendar) ;;
|
|
7|who) who ;;
|
|
8|ls) ls ;;
|
|
9|cat)
|
|
echo 'Please enter the name of the file you wish to see'
|
|
read ANSWER COMMENT
|
|
cat $ANSWER
|
|
;;
|
|
.DE
|
|
.DM
|
|
10|rdb) menu.rdb ;;
|
|
*) echo 'Sorry, but that number or name is not recognized.' ;;
|
|
esac
|
|
.DE
|
|
.PP
|
|
The command
|
|
.B read
|
|
waits for the user to enter his choice.
|
|
The first word typed is assigned to the shell variable
|
|
.BR ANSWER .
|
|
If the user types any more words, they are assigned to variable
|
|
.BR COMMENT ,
|
|
which might be used in your commands.
|
|
.PP
|
|
Next is the
|
|
.B case
|
|
statement that examines
|
|
.B $ANSWER
|
|
to decide which command to execute.
|
|
Note that the number and name
|
|
are separated by a vertical-bar character `|' to mean
|
|
.BR or :
|
|
.DM
|
|
0|exit) exit 0 ;;
|
|
.DE
|
|
.PP
|
|
This line is selected if type either 0 or
|
|
.BR exit .
|
|
The command
|
|
.B exit
|
|
is then executed.
|
|
The double semicolons ``;;''
|
|
are required to show the end of the commands for this
|
|
.B case
|
|
statement.
|
|
.PP
|
|
Each
|
|
.B case
|
|
statement can hold any command or series of commands that you
|
|
could type at your terminal.
|
|
.B esac
|
|
at the bottom is
|
|
.B case
|
|
spelled backwards; it marks the end of the whole
|
|
.B case
|
|
statement.
|
|
.PP
|
|
The expression
|
|
.B *)
|
|
catches any pattern that does not match earlier
|
|
patterns.
|
|
In this case, a message is displayed.
|
|
The pound sign `#' marks the beginning of a comment.
|
|
.PP
|
|
You have great power to do things as a result of
|
|
the user selecting a choice.
|
|
Of course, you need to match the name and number in your
|
|
menu table with the patterns in the
|
|
.B case
|
|
statement;
|
|
it is easy to edit the first part and forget to edit the second.
|
|
.SH "See Also"
|
|
COHERENT Lexicon:
|
|
.B
|
|
case,
|
|
cat,
|
|
clear,
|
|
echo,
|
|
esac,
|
|
ksh,
|
|
read,
|
|
sh
|
|
.R
|