What is Bash File Extension – .sh or nothing

Bash File Extension

Bash File Extension – In this Bash Tutorial, we shall 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. OK, lets take it slow. 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.

Example

Following is an example program with no extension specified, but provided with Hash Bang.

bash-example

Shell

1

2

3

4

5

6

7

#!/bin/bash

# echo command

echoWelcome toTutorialKart

# another echo command

echoLearn BashScripting

Terminal Output

1

2

3

4

5

6

7

8

9

10

11

12

13

~$ls

bash-example

~$cat bash-example

#!/bin/bash

# echo command

echo Welcome toTutorialKart

# another echo command

echo Learn Bash Scripting

~$./bash-example

Welcome toTutorialKart

Learn Bash Scripting

.sh extension

If you do not specify Hash Bang, you may use .sh extension. An example is provided below :