phoboz
Goto Top

Shell dialog --radiolist mit einem ARRAY

Hallo,

Der Anwender wählt aus einer List die aus einem Array (Anzahl var.) erstellt wird, eine Datei für die Installtion von Tomcat aus:

{
#clear
echo "Please select one of the following Tomcat versions"
typeset -a arraytomcat
cd files/tomcat/
arraytomcat=(`find -maxdepth 1 -type f -exec basename {} \;`)
zaehler=0
for value in ${arraytomcat[*]}
do
echo "[""$zaehler""]"" ""$value"
((zaehler=zaehler+1))
done
echo ""
echo "[x] FOR NO TOMCAT INSTALLATION!"
echo ""
echo "YOUR CHOISE: "
read chtomcat
case "$chtomcat" in
x) tomcatver=0;;
*) tomcatver=${arraytomcat[$chtomcat]};;
esac
}


Wollte ganz gerne das ganze mit einer grafischen Oberfläche aufhübschen. "dialog --radiolist"
Weiß allerdings nicht wie ich das ganze mit dem Array auf die Reihe kriege. Wenn man die Optionen die der Anwender hat selbst angibt ist es ja leicht, allerdings können Dateien hinzukommen und die Anzahl varriert.

Content-Key: 218674

Url: https://administrator.de/contentid/218674

Printed on: April 18, 2024 at 23:04 o'clock

Member: Phoboz
Phoboz Oct 08, 2013 updated at 13:18:20 (UTC)
Goto Top
Hallo,

habs nach rumprobieren doch selbst hinbekommen:#

#!/bin/bash
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15  
Leer= ""  

tomcat()
{
typeset -a arraytomcat
cd files/tomcat/
#Arry wird mit den Dateinamen befüllt
arraytomcat=(`find -maxdepth 1 -type f -exec basename {} \;`)
tAnzahl=${#arraytomcat[@]}
tNoChoice="NO TOMCAT INSTALLATION"  
#Listenlänge 
tGroesse=$(($tAnzahl +1))

tzaehler=0
tTemp="dialog --clear --radiolist \"Please select one of the following Tomcat versions (Use your ARROW-Keys to navigate and your SPACE-Key to select)\" 0 0 $tGroesse"  
while [ $tzaehler -lt $tAnzahl ] ; do
tzaehler=$(($tzaehler +1))
tTemp="$tTemp \"${arraytomcat[$(($tzaehler-1))]}\" \""" \" off"  
done

tTemp="$tTemp \"$tNoChoice\" \""" \" off 2> $tempfile"  
eval $tTemp
clear

#Auswahl wird zwischegespeichert
tchoice=`cat $tempfile`
case "$tchoice" in  
$tNoChoice) dialog --msgbox "No Tomcat Installation will be installed" 0 0;;  
$Leer) dialog --msgbox "No Tomcat Installation will be installed" 0 0;;  
*) tomcatver=$tchoice
dialog --msgbox "You selected the following tomcat installation: $tomcatver" 0 0;;  
esac 
}


Grüße

Phoboz