Bash File Extension

Bash File Extension – In this Bash Tutorial, we will learn about the extension provided to Bash Script File.

No extension is required for Bash Script File when you specify Hash Bang, #!/bin/bash , as the first line of code. The Hash Bang is a Kernel convention and helps the Kernel in deciding the interpreter. Kernel deciding the interpreter!! Whats that? The scripts can be in bash, python, perl, php, etc. And specifying the interpreter in Hash Bang is sufficient for your Kernel to execute the Script.

Bash Hash Bang

In this example script, we provide no extension to the script file, but mention the Hash Bang as the first line in the script file.

Bash Script File

</>
Copy
#!/bin/bash

# echo command
echo Welcome to TutorialKart

# another echo command
echo Learn Bash Scripting

Output

~$ ls
bash-example
~$ cat bash-example 
#!/bin/bash

# echo command
echo Welcome to TutorialKart

# another echo command
echo Learn Bash Scripting
~$ ./bash-example 
Welcome to TutorialKart
Learn Bash Scripting

Our script file does not have any extension, and while running the script, ~$ ./bash-example, we have not mentioned any extension.

.sh – Bash Script Extension

In this example, we do not specify Hash Bang as the first line in our script file, but use .sh extension in the file name.

Bash Script File

</>
Copy
# echo command
echo Welcome to TutorialKart

# another echo command
echo Learn Bash Scripting

Output

~$ ls
bash-example  bash-example.sh
~$ ./bash-example.sh
Welcome to TutorialKart
Learn Bash Scripting

Our script file have .sh extension, and while running the script, ~$ ./bash-example.sh, we mentioned the extension.

Concluding this, we have learned how to provide the extension to a bash script file or let the kernel pick up the interpreter with the hash bang in the script file.

Conclusion

In this Bash Tutorial, we learned about the extension for a Bash Script File.