Add: Shebang blog post

This commit is contained in:
Aroy-Art 2023-01-03 17:40:06 +01:00
parent f3579da7b2
commit 4cc1af3083
Signed by: Aroy
GPG key ID: 583642324A1D2070
2 changed files with 54 additions and 0 deletions

View file

@ -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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB