Test d'égalité sur return
Résolu
Bonjour, bonsoir,
Voici ma fonction :
Le souci est que je n'arrive jamais à valider la condition... même si "$?" vaut deux cela ne fonctionne pas...
J'aimerais bien un coup de main :-)
Voici ma fonction :
_getstruct() {
if [ ! -e "$1" ]; then
return 0
elif [ -f "$1" ]; then
return 1
elif [ -d "$1" ]; then
return 2
else
return 0
fi
}
FIRST=$(_getstruct "/home/sacha")
echo $?
if [ $? -eq 2 ] ;then echo "this is a dir";fi
Le souci est que je n'arrive jamais à valider la condition... même si "$?" vaut deux cela ne fonctionne pas...
J'aimerais bien un coup de main :-)
2 réponses
-
ContributeurSalut,
C'est normal, le test est fait sur le code retour de la commande "echo $?" et non sur celui de la fonction.
Pour ça il faut stocker ton code retour :
FIRST=$(_getstruct "$1") retval=$? echo ${retval} if [ "${retval}" -eq 2 ] ;then echo "this is a dir";fi
-
Salut,
En effet quelle quiche !
Je te remercie, à bientôt...