Zu blöd für select....

A

Alphager

Mitglied
Ich bin anscheinend zu blöd für "select" in der bash:
Code:
function _menu(){
 OPTIND=1
   while getopts "a:b:c:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z:" options; do
    case $options in
     a) _A="$OPTARG";;
     b) _B="$OPTARG";;
     c) _C="$OPTARG";;
     d) _D="$OPTARG";;
     e) _E="$OPTARG";;
     f) _F="$OPTARG";;
     g) _G="$OPTARG";;
     h) _H="$OPTARG";;
     i) _I="$OPTARG";;
     j) _J="$OPTARG";;
     k) _K="$OPTARG";;
     l) _L="$OPTARG";;
     m) _M="$OPTARG";;
     n) _N="$OPTARG";;
     o) _O="$OPTARG";;
     p) _P="$OPTARG";;
     q) _Q="$OPTARG";;
     r) _R="$OPTARG";;
     s) _S="$OPTARG";;
     t) _T="$OPTARG";;
     u) _U="$OPTARG";;
     v) _V="$OPTARG";;
     w) _W="$OPTARG";;
     x) _X="$OPTARG";;
     y) _Y="$OPTARG";;
     z) _Z="$OPTARG";;
    esac
   done

_MENUARRAY=("$_A" "$_B" "$_C" "$_D" "$_E" "$_F" "$_G" "$_H" "$_I" "$_J" "$_K" "$_L" "$_M" "$_N" "$_O" "$_P" "$_Q" "$_R" "$_S" "$_T" "$_U" "$_V" "$_W" "$_X" "$_Y" "$_Z" )
echo Menuarray gemacht
select _OPTION in $_MENUARRAY;
do
echo $_OPTION
done
}
Ich habe mit dem Code meherere Probleme:
1. Select zeigt beim Aufruf von _menu -a Test1 -b Test2 nur Test1 an.
2. Ich habe eine Endlosschleife; ich kann sooft ich will ein Item auswählen und komme trotzdem aus select nicht raus.

Wo sitzt mein Denkfehler ?
 
Ich würde dir ein shift nach dem esac empfehlen.
 
Das bewirkt nichts (und ist soviel ich weis bei getops unnötig)
 
Hallo,

dann probiers doch mal hiermit:

Code:
function _menu(){
 OPTIND=1
   while getopts "a:b:c:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z:" options; do
    case $options in
     a) _A="$OPTARG";;
     b) _B="$OPTARG";;
     c) _C="$OPTARG";;
     d) _D="$OPTARG";;
     e) _E="$OPTARG";;
     f) _F="$OPTARG";;
     g) _G="$OPTARG";;
     h) _H="$OPTARG";;
     i) _I="$OPTARG";;
     j) _J="$OPTARG";;
     k) _K="$OPTARG";;
     l) _L="$OPTARG";;
     m) _M="$OPTARG";;
     n) _N="$OPTARG";;
     o) _O="$OPTARG";;
     p) _P="$OPTARG";;
     q) _Q="$OPTARG";;
     r) _R="$OPTARG";;
     s) _S="$OPTARG";;
     t) _T="$OPTARG";;
     u) _U="$OPTARG";;
     v) _V="$OPTARG";;
     w) _W="$OPTARG";;
     x) _X="$OPTARG";;
     y) _Y="$OPTARG";;
     z) _Z="$OPTARG";;
    esac
   done

_MENUARRAY=""$_A" "$_B" "$_C" "$_D" "$_E" "$_F" "$_G" "$_H" "$_I" "$_J" "$_K" "$_L" "$_M" "$_N" "$_O" "$_P" "$_Q" "$_R" "$_S" "$_T" "$_U" "$_V" "$_W" "$_X" "$_Y" "$_Z""
echo Menuarray gemacht
select _OPTION in $_MENUARRAY;
do
echo $_OPTION;
break
done
}
 

Ähnliche Themen

bash esac problem

verzeichniss suche funktioniert nicht

Shellskript - Fehler in Cron

Auf zusaetzliches Argument pruefen

getopts - ordentliche Parameternamen?

Zurück
Oben