When working with shell scripts in Linux, understanding the appropriate file extension is crucial for efficient development and maintainability. One commonly asked question by new Linux users is, “What is the file extension of a shell script?” This article will answer that and cover all aspects of the bash file extension. You will also learn the different naming conventions, best practices, and how to make your bash script executable.
In this tutorial you will learn:
- What is the extension of a shell script?
- Best practices for bash file naming conventions
- Examples of creating bash scripts

Category | Requirements, Conventions or Software Version Used |
---|---|
System | Linux system (e.g., Ubuntu 20.04, Fedora, CentOS) |
Software | Bash shell version 4.0 or newer |
Other | Text editor (e.g., nano, vim) |
Conventions | # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
NOTE
Using a .sh extension is a good practice, but it has no bearing on the script’s functionality. Bash scripts can run without any specific extension, as long as they have the correct shebang and execute permissions.
The suffix for a bash script is typically .sh
. This suffix is useful for easily recognizing the script type but is not required for functionality. A bash script can run without a specific suffix, as long as it has the correct shebang and execute permissions.
Best Practices for Bash Script Extensions
Here are some guidelines for naming your bash script files:
- Use the
.sh
extension to denote that the file is a shell script. - Use descriptive names to identify the functionality of the script, e.g.,
backup_script.sh
. - Avoid spaces in filenames; instead, use underscores (e.g.,
my_script.sh
).
- Creating a Simple Bash Script: Let’s start by creating a simple bash script. This script will simply output a string “Hello, World!” to the terminal.
#!/bin/bash echo "Hello, World!"
This script uses the
#!/bin/bash
shebang to specify the interpreter, which is the bash shell. Theecho
command is then used to print “Hello, World!” to the console. - Making the Script Executable: After creating a bash script, you need to make it executable. To do this, use the
chmod
command as shown below.$ chmod +x my_script.sh
Thechmod +x
command grants execute permissions to the script, allowing it to be run as an executable file. Now, you can run the script using./my_script.sh
. - Executing the Script: Once the script has been made executable, you can run it from the terminal. To do so, use the following command:
$ ./my_script.sh
Running the script will output “Hello, World!” to the terminal, confirming that it is functioning as expected.
Executing script with .sh extension
Conclusion
Using an appropriate bash file extension such as .sh
is essential for maintaining a well-organized scripting environment. While technically optional, it helps identify the type of file and makes collaboration easier. Remember that bash scripts should be named descriptively and be given proper execute permissions. With the information provided in this tutorial, you should now have a solid understanding of bash file extensions and how to create and execute shell scripts effectively.