Dynamic menu in shell script

April 16, 2011 at 23:15:51
Specs: Solaris 10

Hi,

I want to provide a menu in a shell script that offers a selection of nodes to connect to and I'm struggling!

The selection of nodes is being constantly updated, so I want the menu to reference a hosts file as opposed to updating the shell script constantly. I can use select to create such a dynamic menu, but I am at a loss as to how to incorporate case into this dynamic scenario.

I don't actually need to execute a function or anything like that per selection, I just want to be able to feed the user's choice in to a variable. At some point I will also need to be able to make multiple selections and this is another thing I'm at a loss on how to do!

Any help is very greatly appreciated!

Alan.


See More: Dynamic menu in shell script

Report •


#1
April 18, 2011 at 12:45:48

As you have undoubtedly seen the case statement is not dynamic. One way to do is to have two scripts. Let's say your driver script is called menu_driver and another script called menu.

Within menu_driver, determine if the hosts file is newer than the menu script. If it is, automatically recreate the menu script which will rebuild the case statement based on what is in the hosts file.

You might have a timing issue if a user is in the menu script at the same time the hosts file is changed. That change wouldn't be reflected until the menu program is re-executed.

I realize that isn't the easiest solution to implement.


Report •

#2
April 19, 2011 at 01:34:55

I'd never thought about using 2 scripts, so that is in fact a great solution, many thanks!

Report •

Related Solutions


Ask Question