diff --git a/content/blog/2022-05-25-shebang-#!-tutorial-in-linux.md b/content/blog/2022-05-25-shebang-#!-tutorial-in-linux.md new file mode 100644 index 0000000..1caffb8 --- /dev/null +++ b/content/blog/2022-05-25-shebang-#!-tutorial-in-linux.md @@ -0,0 +1,54 @@ +--- +title: "Shebang #! Tutorial In Linux" +description: "" + +date: 2022-05-25T12:50:05.057Z +lastmod: 2023-01-03T16:39:00.682Z + +image: /images/blog/shebang.jpg + +draft: false + +tags: + - Linux + - Cheat-Sheet + +slug: shebang-tutorial-linux +--- +# Shebang #! Tutorial In 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 + * [Intro](#shebang--tutorial-in-linux) + * [Shebang Syntax](#shebang-syntax) + * [Common Shebangs](#common-shebangs) + * [Conclusion](#conclusion) + +## 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 | +|----------------|--------------------| +| 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. \ No newline at end of file diff --git a/static/images/blog/shebang.jpg b/static/images/blog/shebang.jpg new file mode 100644 index 0000000..2a28c0a Binary files /dev/null and b/static/images/blog/shebang.jpg differ