2

I am new to Whiptail.

I would like to create a program that allows user to show the information of certain things, such as network cards.

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

eth0 lo

However, if changes are made, for example another network card was added named lo1, the program will update the changes and allow user to have the latest set of choices:

eth0 lo lo1

I am up to here at the moment. guide me guys..

#!/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,

Hcl

neminem
  • 2,658
  • 5
  • 27
  • 36
Minorsee
  • 67
  • 10

1 Answers1

1

I'm assuming the problem is that you need duplicated name pairs for whiptail and you aren't sure how to get from your list to there?

In which case something like this might work better:

read -ra array <<<$(ifconfig -a | awk '!/^ / && NF {print $1; print $1}')
whiptail --title Networking --menu "select your choice" 16 78 5 "${array[@]}"

Read this page for why you want to use the read -a construct.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • I meant like i want the output to be like, lets say i have two item in the array, i want the output to be like one after another, instead of side by side which the current code is doing. – Minorsee Jul 19 '14 at 09:59
  • Okay, so after inserting your code, The output are as such http://i57.tinypic.com/mm3pxs.jpg How do i make it like so that i wont duplicate? – Minorsee Jul 19 '14 at 10:03
  • 1
    That's a whiptail thing. Use one of `--notags` or `--noitem` to tell whiptail not to show whichever of those you don't want it to show. – Etan Reisner Jul 20 '14 at 02:08