Friday, August 22, 2014
12:35 AM

Creating GUI of menu list in linux scripts

In the post we saw how to install whiptail and use it to create GUI in a linux terminal. Taking it a step further, let us see how to create menu like list like GUI in a linux terminal.

The option to be used for creating a menu is --menu, the syntax being



The value and description pair being the main part of the menu list. The value is the value that is assigned to the menu item and what follows is its description.

Example





 photo whip_menu_1.png

In the above Example A is the value Menu1 its description, B is the value and Menu2 its description. We can any number of such menu value pairs.

We can move between these menu value pairs using the arrow keys and which ever menu we select and press enter, that value of that menu item is sent to the standard error.

In the above example, if we press enter by selecting "B Menu2", value B is sent to the standard error.

To be able to store this value for futher use in a script we need to redirect the standard error to value, which can be done by swapping the file descriptors of standard output and standard error.



Which ever option is chosen the value of the same gets stored in the variable option.

Here is an example script which makes use of the menu list to get data from the user.



Give the script execute permission and run it to see the output



 photo whip_menu_2.png

 photo whip_menu_3.png


0 comments:

Post a Comment