In a Bash script, how can I exit the entire script if a certain condition occurs? September 7, 2022 by Tarik Try this statement: exit 1 Replace 1 with appropriate error codes. See also Exit Codes With Special Meanings.