
April 6th, 2011, 04:26 AM
|
|
|
This will cover quite a few of the basic concepts in scripts. As it's a learning exercise it would be unfair just to hand you a ready-to-run script. A lot of the learning is done by making errors and finding out why they are errors and fixing them. So ... let's start with some basic hints!
I would use functions to handle the details of running of the actual commands (getting options, etc.). It will just make things a little tidier and self-contained.
You will want to output the menu in a loop - exiting once the user selects the 'exit/quit' option. The user selection should also be in a loop, until they pick a valid selection.
Thus, in pseudo-code, something like:
Code:
functionA () {
}
functionB () {
}
ShowMenu() {
say "A) - Run ps"
say "B) - Run top"
say ""
say "Q) - Quit"
}
choose=""
while $choose <> "Q"
ShowMenu
valid=0
while $valid = 0
say "Enter choice: "
read choose
case $choose
when "A"
functionA
valid=1
when "B"
functionB
valid=1
when "Q"
say "Goodbye!"
valid=1
exit
otherwise
say "Invalid option!"
valid=0
end-case
end-while
say "Press enter to continue"
end-while
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
|