Dynamic menu selection? Help..


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Dynamic menu selection? Help..
# 1  
Old 07-18-2014
Dynamic menu selection? Help..

Hi guys, i would like to create a program that allow user to show the information of certain thing such as network card.

I would like the menu to be dynamic, for example:
my computer system have 2 network card inserted at the moment, therefore the menu will have 2 choice for the user.

eth0
lo

However, if there's changes made, for example another network card was added which name lo1. The program will update the changes and allow user to have the latest choice.

eth0
lo
lo1

I am up to here at the moment. guide me guys..
Code:
#!/bin/bash
clear

ifconfig -a | sed -n 's/^\([^ ]\+\).*/\1/p' > somefile

array=($(<somefile))

whiptail --title Networking --menu "select your choice" 16 78 5 "${array[@]}"

Regards,

Malfolozy

Last edited by malfolozy; 07-18-2014 at 07:47 PM.. Reason: code tags please
# 2  
Old 07-18-2014
What's your system? There may be more convenient ways than ifconfig to get device names.

Dumping data into arrays is often -- usually -- not the answer.

BASH -- and most modern Bourne shells -- has a built-in automatic menu, which acts like a while loop:

Code:
select X in a b c d q
do
        echo "You chose $X"
        [ "$X" = "q" ] && break
done

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 07-19-2014
Hi Corona668,

My system is Linux, Red hat.

I am working on the Whiptail script, not Select. Therefore, its kinda hard to make a dynamic menu as a beginner. Guide me pls,

Thanks,

Malfolozy
# 4  
Old 07-19-2014
Hi try:
Code:
array=($(ifconfig -a | sed -n 's/^\([^ ]\+\).*/\1 \1/p') )

You need two strings per item..
This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 07-19-2014
Hello Scrutinizer,

After i try it in my code,

the output are as such

http://i57.tinypic.com/mm3pxs.jpg

Is there anw to remove the duplicate into something else like number for the choices?

Thanks,

Malfolozy
# 6  
Old 07-19-2014
You could try:

Code:
array=($(ifconfig -a | awk '{print $1, "Interface_"NR}' RS= ) )

There are many possibilities
This User Gave Thanks to Scrutinizer For This Post:
# 7  
Old 07-19-2014
Yay! The first code works!!

After that, how do i go about doing the code for the choices?

I forward the choice chosen by the user to a file "somefile" by using this

Code:
2>somefile

and this is the code for choice that i want it to be, how do i go about doing this? the chosen network card part.

Code:
CHOICE=$(cat somefile)

case $CHOICE in

"$(cat somefile)") echo $(ifconfig (chosen networkcard))

esac

Thanks,

Malfolozy

Last edited by malfolozy; 07-19-2014 at 08:16 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dialog --menu limitation for the entries for selection

Hi Guys, Please pardon me if this is a silly question, but I have tried to find an answer and going through the man page and failed to get one. I have created a menu driven script with dialog --menu option. Everything is working as expeted, however, it seems that if I have more than 10... (1 Reply)
Discussion started by: ww889
1 Replies

2. Shell Programming and Scripting

A selection menu in a shell script

I'm writing a shell script and have a problem with selection when I issue the command, is there a way to automatically choose a selection number one after a selection menue appear Command 1-choice 2- choice 3-choice Thanks Sara (3 Replies)
Discussion started by: Sara_84
3 Replies

3. Web Development

Dynamic Drop Down Menu

I need to create a dynamic drop down menu which is populated by entries such as; htdocs/client1/index.php htdocs/client2/index.php htdocs/client3/index.php htdocs/client4/index.php etc. So htdocs/client*/index.php Is this possible? I know how to do this using normal arrays, but not... (2 Replies)
Discussion started by: JayC89
2 Replies

4. Shell Programming and Scripting

reprint the select menu after a selection

Hi, I am using a select in ksh for a script #!/bin/ksh FIRSTLIST='one two three four quit' PS3='Please select a number: ' select i in $FIRSTLIST ; do case $i in one) print 'this is one' ;; two) print 'this is 2' ;; three) print 'this is 3' ;; four) print... (7 Replies)
Discussion started by: omerzzz
7 Replies

5. UNIX for Dummies Questions & Answers

Input A Menu Selection In A Variable

hey all, me again....having a problem with my code, where I essentially am trying to show a menu, have the user select an option (from 1 to 5), then display which selection they picked... #!/bin/bash # A LIST OF THE ERROR MESSAGES AND THE PROPER SYNTAX: error_0="Correct amount of... (1 Reply)
Discussion started by: SoVi3t
1 Replies

6. Linux

Opt out of selection menu?

When I logon to my server with PuTTY I am forced into a selection menu with few options. How to I opt out of this menu to get to the home directory to view all of the files on the server? Thanks for the help. :o (1 Reply)
Discussion started by: ksirimarco
1 Replies

7. Shell Programming and Scripting

Menu help with array selection

Hi there all I got the following I got multiple arrays named for example STAT_AAAA STAT_AAAB STAT_AAAC STAT_AAAD Now what I want I have chosen an option in a menu to select 1 but I dont want to write for all the same thing so I made it a signle one now what I want is to get STAT_ and... (6 Replies)
Discussion started by: draco
6 Replies

8. Shell Programming and Scripting

Dynamic Menu Help

I'm working on a menu to read folders in as menu selections then CD to the selected folder and display the contained files as menu selections for execution. I'm using the following to read in the file list but I get lost after that. I only read in files that begin with CAPs. The problem is... (3 Replies)
Discussion started by: ScottKe
3 Replies

9. Shell Programming and Scripting

dynamic Select menu

Hi all is menu driven by SELECT can be a dynamic ? My requirement is that i want SELECT to be created on run time not predefine . The select should be created as per the no of words in a file thanks in advance rawat (2 Replies)
Discussion started by: rawatds
2 Replies
Login or Register to Ask a Question