This article describes what the shebang is, and how to use it to make sure that your script files run correctly.
The shebang is a special character sequence in a script file that specifies which program should be called to run the script. The shebang is always on the first line of the file, and is composed of the characters #! followed by the path to the interpreter program. You can also specify command line options, if necessary.
For example, the following line contains the shebang, the path to the Perl interpreter, and the command line option -w:
The shebang is especially important for CGI script files. For example, if a file named script.cgi contains the previous shebang line, you can run it from the command line by simply typing:
Similarly, the Apache web server is able to run the file as a CGI script, because it knows it must call the Perl interpreter.
The following table shows the correct shebangs to use in script files that run on A2 Hosting web servers:
There is an alternative to using absolute paths to the interpreter in shebang lines. To make your script files more portable across different systems, you can use the env program to determine the path to the interpreter. For example, consider the following shebang line:
This example locates and runs the Ruby interpreter, whether it is located in the /usr/bin/ directory, the /usr/local/bin/ directory, or somewhere else. You do not have to know the absolute path to the Ruby interpreter, because the env program figures it out at runtime.
For more information about the shebang, please visit http://en.wikipedia.org/wiki/Shebang_%28Unix%29.