[Shell] imbrication if ... else

Résolu
tonio4531 -  
 tonio4531 -
Bonjour à tous,
Je suis face à une autre, en fait je désire réaliser des tests genre if ... else if en ksh

Voici mon code :
[code]
if [ $COM = 'ALL' ]

if [ $EXP = 'A']
then
echo "ALL A"
elif [ $EXP = 'I' ]
then
echo "ALL I"
else
echo "ALL E"
fi

elif [ $COM = 'K' ]
if [ $EXP = 'A' ]
then
echo "K A"
elif [ $EXP = 'I' ]
then
echo "K I"
else
echo "K E"
fi
fi
[/code]

En gros dans l'esprit c'est ça.

Mais il bloque sur le elif [ $COM = 'K' ]

Savez-vous pourquoi ? y'a -t-il une limite dans le nombre d'imbrication qu'il est possible de faire sous ksh.

Merci par avance pour vos réponses.
Cdlt,
Configuration: Windows 2000
Firefox 2.0.0.9

1 réponse

  1. lami20j Messages postés 21506 Date d'inscription   Statut Modérateur, Contributeur sécurité Dernière intervention   3 571
     
    Salut,

    je n'ai pas testé ton code, mais à la première vue il manque un then (voir en gras)
    si tu indentes ton code tu gagneras en visibilité ;-)
    if [ $COM = 'ALL' ]
    then
     if [ $EXP = 'A']
     then
      echo "ALL A"
     elif [ $EXP = 'I' ]
     then
      echo "ALL I"
     else
      echo "ALL E"
     fi
    elif [ $COM = 'K' ]
     if [ $EXP = 'A' ]
     then
      echo "K A"
     elif [ $EXP = 'I' ]
     then
      echo "K I"
     else
      echo "K E"
     fi
    fi
    
    5
    1. tonio4531
       
      oki je te remercie ça marche impec maintenant !
      0