Shell Script Shebang

The #! syntax is used in scripts to indicate an interpreter for execution under UNIX / Linux operating systems. The directive must be the first line in the Linux shell script and must start with shebang #!.

The sharp sign (#) and the bang sign (!) thats why called is the shebang. (sharpbang)

Shebang starts with #! characters and the path to the bash or other interpreter of your choice. Make sure the interpreter is the full path to a binary file. For example: /bin/bash.

sleep 300
  • If a script does not contain a shebang the commands are executed using your shell.
  • you can print SHELL variable to show which shell you are using.
  • Different shells have slightly varying syntex
  • you can see all the available shells in /etc/shells file in Linux operating system.
  • It makes shell scripts more like actual executable files,
  • because they can be the subject of 'exec'
  • If you do a 'ps' while such a command is running, the real name appears instead of 'sh' or 'bash'. Likewise, system accounting is done based on the real name.
  • It will allow other interpreters to fit in more smoothly.
└─$ cat /etc/shells
#!/bin/sed -f
#!/bin/awk -f

let's run a script with other interpreter. create a file using the below snippts

print("Hello this is python script")

now let's change the mode and give the execute permission to file. and execute it.

└─$ chmod +x
└─$ ./
hello world from python program

Demo Video

Click Here for Demo Video