Shebang / Hashbang

Senthil Nayagan
2 min readOct 27, 2018

--

Shebang/Hashbang

What is Shebang or Hashbang?

In computing, a shebang aka hashbang is a special character sequence consisting of a hash sign (#) and an exclamation mark (!) at the beginning of a script like this: #!.

In UNIX / Linux operating systems, #! syntax used at the beginning of the script is to indicate an interpreter for execution. The shebang i.e. #! takes an argument which is always the path to the interpreter that will be used to interpret the script itself.

Thus, the syntax is as follows #! interpreter [argument] in which interpreter is an absolute path to an executable program/interpreter followed by the “optional” argument in case the interpreter requires it. For instance, #!/bin/sh where the program loader is instructed to run the program /bin/sh.

Note: Many scripting languages use the # character to indicate the beginning of a comment line that should be ignored by the interpreter. However, the shebang is a special exception to this rule.

Examples

  • #!/bin/sh – Execute the file using the Bourne shell, or a compatible shell, with path /bin/sh.
  • #!/bin/bash – Execute the file using the Bash shell.
  • #!/usr/bin/python – Execute using Python by looking up the path to the Python interpreter.
  • #!/bin/false – Do nothing, but return a non-zero exit status, indicating failure.

--

--

Senthil Nayagan
Senthil Nayagan

Written by Senthil Nayagan

I am a Data Engineer by profession, a Rustacean by interest, and an avid Content Creator.