[Shell] imbrication if ... else

Résolu/Fermé
tonio4531 - 28 mai 2008 à 17:52
 tonio4531 - 29 mai 2008 à 09:48
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,
A voir également:

1 réponse

lami20j Messages postés 21331 Date d'inscription jeudi 4 novembre 2004 Statut Modérateur, Contributeur sécurité Dernière intervention 30 octobre 2019 3 567
28 mai 2008 à 20:40
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
oki je te remercie ça marche impec maintenant !
0