Exiting a running Bash Script in Terminal
If for some reason a bash script is running too long and you want to exit its execution, then you can make press the keyboard keys Control + C.
Example:bash-3.2$ ./script.sh
^C
bash-3.2$
When you press Control + C you will see a ^C character displayed on the Terminal and you are returned back to the bash shell prompt.

Exiting a Script from within a Bash Script
On the other hand if you want to exit the script from within it, then you can make use of the exit 0 command. When this command is encountered while execution the script will terminal and return back to the prompt.
Example:#!/bin/bash
sleep 10
exit 0
echo "Hello there"
When you run the above script, it exits at line number 2, and the 3rd echo line is not printed.

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!