Unix Shell Shebang Hack #!

By Xah Lee. Date: . Last updated: .


What is Unix Shebang?

the shebang line is a line like this in the beginning of file:


echo "something"

suppose that file is name xx.

normally, to run the file, you need to call the programing language with argument of the file name, like this:

sh xx

but with shebang, you can run it just by typing xx.

The Unix Shebang is a Hack

the unix shebang is a hack. Lots problems.

The advantage it brings, is mostly just shorter typing. This can be achieved propertly by defining a shell alias.

Who owns the first line of file?

Shebang wants to own the first 2 chars of a file and first line. But, so do others, witness:

The Unicode: BOM, Byte Order Mark wants to be on first char.

The File encoding declaration, used by emacs, ruby, python 2, normally wants to be on first line:

#-*- coding: utf-8 -*-.

so, there's this precious first line. Who gets to use it?

O, so file name extension is a ugly stupidity of Microsoft Windows, but it's ok if it's moved into the first line of your file?

A better design is a meta-data scheme. Examples: