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.

-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Bash,
- Bash Hello World! Script Tutorial
- How to run bash command in background
- How to create new user account in Windows bash
- How to Compare Strings in Bash
- Bash: Allow Command to Fail without exiting Script
- Fix bash: script.sh: Permission denied Error
- Bash getopts Command Example
- How to fix bash ping command not found error
- How to add NewLine Character in Bash Script String
- How to Echo Bash Command to a File
- Bash Command to Find String in a File
- How to open new Terminal using Bash Command
- Bash How to Save Output of a Command to a Variable
- Download a SSL Certificate from a URL in Terminal
- Bash Command to Check IP Address
- Know Bash shell version command
- Bash Command To Check If File Exists
- How to run a Command in Bash Script
- How to Compare two Files in Bash Shell
- How to check if a variable is set in Bash Script or Not
- Convert String from uppercase to lowercase in Bash
- How to see Created Accessed Modified and Changed dates of a file using bash terminal command
- Bash Command To Get Current Time
- Bash command to List Files
- Fix: bash: syntax error near unexpected token
More Posts:
- How to write JSON file in Python Program - Python
- Pretty Print JSON String in Java Console Output - Java
- Install node on Alpine Linux Docker - Docker
- Java JDBC IN Clause Example with PreparedStatement MySQL - Java
- How to Get the List of Shells on Linux - Linux
- How to add Spring Repository to Maven pom.xml - Java
- SharePoint 2010 DataForm Unable to display this Web Part System.StackOverflowException - SharePoint
- Java 8: Convert Date between Time Zones Example - Java