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
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.