mercredi 3 février 2016

The correct syntax for if...elif...else in Bash [duplicate]

This question already has an answer here:

I'm a beginner when it comes to shell scripts, and learning it in college FOSS lab. I have seen two different syntax for the if statement, and both are working, so am not sure what is the right one that I should stick into.

if [ condition ]
then
    # statements
else
    # statements
fi

This was the one I found in our class books, and it is indeed working in bash. The next syntax I found online was with an extra ; symbol, like this.

if [ condition ]; then
    # statements
else
    # statements
fi

What is the difference between the two? And which is the good practice to stick to?

Aucun commentaire:

Enregistrer un commentaire