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:
#!/usr/bin/perl -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:
./script.cgi
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:
Language | Shebang |
---|---|
Perl | #!/usr/bin/perl |
Python (generic) | #!/usr/bin/python |
Python (specific version) | #!/usr/bin/python2.7 #!/usr/bin/python3.6 ... etc. |
Ruby | #!/usr/bin/ruby |
PHP | #!/usr/local/bin/php |
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:
#!/usr/bin/env ruby
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_(Unix).
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.