What is the shebang ( #!/bin/bash).

7,596

When a file script starts with the shebang directive

#!langpath args

and has execution permissions set, Unix will "replace it" by

exec langpath args path-to-the-script.

This ways, typically:

  • langpath defines the language to be used, ans should be the path of an executable interpreter of the (programming) language (ex: '/usr/bin/python')
  • the language should accept a script file as an argument
  • the language should ignore the #!... directive as a comment
Share:
7,596

Related videos on Youtube

Ashish Kumar Thakur
Author by

Ashish Kumar Thakur

A Linux enthusiastic, Love to learn about new technology.

Updated on September 18, 2022

Comments

  • Ashish Kumar Thakur
    Ashish Kumar Thakur over 1 year

    why do we use shebang in the beginning of a shell script file. does the script will run without it.

    I tried running it without shebang in shell script but it didn't run.

    • guiverc
      guiverc about 6 years
      the #! helps the interpreter recognize the code; be it sh, bash, tsch, csh, ksh, .. perl, python .... (which at times can look alike for short scripts) [and thus know which interpreter is required to run it]
  • Ashish Kumar Thakur
    Ashish Kumar Thakur almost 6 years
    Thank you so much, its really helped me to understand the concept of using shebang.
  • max
    max almost 6 years
    @AshishKumarThakur, I am glad it help.