mardi 29 novembre 2016

What is good coding practice in BASH with regard to exiting

What is good practice when writing a BASH script with regards to exiting the script when using functions and if statements?

1)

functionONE(){
    some code here
    exit 0
}

functionTWO(){
    some code here
    exit 0
}

if [[ condition ]]; then
    functionONE
else
    functionTWO
fi

exit 1

2)

functionONE(){
    some code here
}

functionTWO(){
    some code here
}

if [[ condition ]]; then
    functionONE
    exit 0
else
    functionTWO
    exit 0
fi

exit 1

Or would scenario create an endless loop? (Would the exit 0 in the second scenario be executed after the functions have run or would it never be reached

Ideally the bottom line would never be reached.

Aucun commentaire:

Enregistrer un commentaire