Unix Shell Shebang Hack #!
NEVER ADD A SHEBANG LINE IN YOUR SCRIPT.
What is Unix Shebang?
the shebang line is a line like this in the beginning of file:
#!/bin/sh 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:
but with shebang, you can run it just by typing
The Unix Shebang is a Hack
the unix shebang is a hack. Lots problems.
- It depends on the programing language's comment syntax being a number sign
- It wants to own the first first line of a file, for a purpose not related to the script.
- It induces user to not have a clear idea between scripts and binary apps. (this in turn induces misunderstanding, and security holes)
- It reduces clarity of what script is written in what lang, because the script can add arbitrary shebang line.
- Shebang line is not portable. On different machines, the program may be located elsewhere, or same path but not the intended version.
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: