• [^] # Re: Complètement imbitable...

    Posté par (site web personnel, Mastodon) . En réponse au journal astuce bash: de l'usage du elif. Évalué à 6.

    Je ne te dis pas de faire 15 fonctions, une pour chacun de tes tests, mais une où tu fais tes traitements, pour pouvoir faire un return. Ou alors tu peux faire des exit, mais en général on évite de mettre 15000 exit dans un programme. Code non testé, toussa...

    E_FOO=1
    E_BAR=2
    E_JIZ=3
    result=`foo`
    if ! $result ; then 
     error "something went wrong trying to run foo"
     return E_FOO
    fi
    echo "I did run foo"
    echo "Now I'm going to run bar"
    result=`bar`
    if ! $result ; then 
     error "something went wrong trying to run bar"
     return E_BAR
    fi
    echo "I did run bar"
    echo "Now I'm going to run jiz"
    result=`jiz`
    if ! $result ; then
     error "something went wrong trying to run jiz"
     return E_JIZ
    fi
    echo "I could go on like this forever"