Click here to show toolbars of the Web Online Help System: show toolbars
awk -v CMDFILE="uucp_commands" '# invoke -- menu-based
# command generator
# first line in CMDFILE is the title of the menu
# subsequent lines contain: $1 - Description;
# $2 Command to execute
BEGIN { FS = ":"
# process CMDFILE, reading items into menu array
if ((getline < CMDFILE) > 0)
title = $1
else
exit 1
while ((getline < CMDFILE) > 0) {
# load array
++sizeOfArray
# array of menu items
menu[sizeOfArray] = $1
# array of commands associated with items
command[sizeOfArray] = $2
}
# call function to display menu items and prompt
display_menu()
}
# Applies the user response to prompt
{
# test value of user response
if ($1 > 0 && $1 <= sizeOfArray) {
# print command that is executed
printf("Executing ... %s\n", command[$1])
# then execute it.
system(command[$1])
printf("")
# wait for input before displaying menu again
getline
}
else
exit
# re-display menu
display_menu()
}
function display_menu() {
# clear screen -- if clear does not work, try "cls"
system("clear")
# print title, list of items, exit item, and prompt
print "\t" title
for (i = 1; i <= sizeOfArray; ++i)
printf "\t%d. %s\n", i, menu[i]
printf "\t%d. Exit\n", i
printf("Choose one: ")
}' -