Bash – In a Bash script, how can I exit the entire script if a certain condition occurs

bashexitexit-codescripting

I'm writing a script in Bash to test some code. However, it seems silly to run the tests if compiling the code fails in the first place, in which case I'll just abort the tests.

Is there a way I can do this without wrapping the entire script inside of a while loop and using breaks? Something like a dun dun dun goto?

Best Answer

Try this statement:

exit 1

Replace 1 with appropriate error codes. See also Exit Codes With Special Meanings.