Aroy-Art-Site/content/blog/2022-05-25-shebang-#!-tutorial-in-linux.md

1.9 KiB

title description date lastmod image draft tags slug
Shebang #! Tutorial In Linux 2022-05-25T12:50:05.057Z 2024-09-11T21:10:00.957Z /images/blog/shebang.jpg false
Linux
Cheat-Sheet
shebang-tutorial-linux

In computing and Linux the shebang is a character sequence that consists of # and !. Simply the shebang is expressed as #!. The shebang is also called sha-bang, hashbang, pound-bang, and hash-pling. The shebang is used to specify an interpreter for script files. Linux is popular with its script files and scripting languages like Bash, ZSH, Python, Perl, PHP, etc. The shebang is used to specify the interpreter type and location. When a script file is called the first line contains the shebang with the interpreter path.

Table of content

Shebang Syntax

The shebang has the following syntax where the interpreter executable file path is appended after the shebang.

#!INTERPRETER
  • INTERPRETER is the interpreter path like “/etc/bash” etc.

Common Shebangs

Type / Language Syntax
Sh #!/bin/sh
Bash #!/bin/bash
ZSH #!/bin/zsh
Python 3 #!/bin/python3
PHP #!/bin/php
Perl #!/bin/perl

Conclusion

Let me answer a few more questions before ending this article:

  • It is important that there is no space between # and !. You CANNOT use it like this: # !/bin/bash.
  • Most system allow space between #! and /bin/bash however it is a good practice to avoid space between #! and /bin/bash.
  • #! has to be on the first line, otherwise the shebang line will be treated as comment. You cannot even have a blank line before it.