Bash scripts and functions are helpful
This is an old thread, but I was happy to find it. Perhaps you came here needing a solution to a menuing problem like the one originally posted. I have (over many years) worked to find a solution to this same problem. I will share it with you.
I have found Bash scripts and functions to helpful in treating this common problem. Scripts and functions do things for you. They can use logic and variables. Scripts can do just about anything that you can do at the keyboard. Functions are handy for certain kinds of operations like changing environment variables or the current directory
For me the challenge was organizing my scripts and functions. I wrote a script called "menu" which is always in the PATH. When you run menu the list of scripts currently in the PATH and functions currently set are displayed by use of less. Next to each script or function is displayed a short description of how to use it. Some scripts/functions just run. Others need extra information, called arguments, to be listed after. This is just normal linux syntax.
I also wrote a script bound.f that sets a function called "bound" Function "bound" is always set. It takes an argument, $1. When you run "bound $1" then PATH is changed to include $1 in PATH and to run any function definitions found at $1, setting the functions in the current environment. It also unsets any functions that were previously set by use of bound and removes from PATH anything previously added by use of bound. Actually, there's more that I haven't explained.
If you're paying attention you will see the power and usefulness of this method. It is general purpose and flexible. Here is an example of its use:
pdata; not_host; r_dwa
I used this today. By a previous use of bound a function "pdata" had already been set. Using pdata invokes "bound $env_always/pindex" where env_always had already been defined. This use of bound sets function "not_host". Using not_host invokes "bound /mnt/joresorc/not_host". This use of bound puts script r_dwa in PATH. Using r_dwa displays password and login information I had previously put in file r_dwa.dat.
On one command line above I selected a collection of "pdata" scripts and functions, then used one of them called "not_host" which in turn selected a collection of scripts and functions, then used one of them called "r_dwa" which displayed the information I needed.
I could have run each of the three commands above separately:
pdata
not_host
r_dwa
After each of the above I could have used the "menu" command. I didn't, because I have the menus memorized. When I need some help, then I use them "menu" command.
I hope this helps those of you who have come to this thread. Good luck in your search for a good way to make menus.
|