Scripting is such a great way to relax. Well, at least in my eyes, that’s a great way to relax. Scripting can be as easy as telling your OS it needs to do something at a specific time or as complicated as synchronizing multiple folders on various servers on various platforms. (Insert example here). I thought it would be fun to post a little `Computer Science 101` here. Most of us Developers love our terminal (possibly even the Microsoft lovers), and we all know how to start off a basic shell application or script. Shebang, Hashbang.. what ever you call her, she is there to get your script aimed in the right direction.
In computing, a shebang (also called a sha-bang, hashbang, pound-bang, hash-exclam, or hash-pling) is the character sequence consisting of the characters number sign and exclamation mark (that is, “#!”) when it occurs as the initial two characters on the initial line of a script.
Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest of the script’s initial line as an interpreter directive; the specified interpreter program is run instead, passing to it as an argument the path that was initially used when attempting to run the script. For example, if a script is named with the path “path/to/script”, and it starts with the following line:
then the program loader is instructed to run the program “/bin/sh” instead (usually this is the Bourne shell or a compatible shell), passing “path/to/script” as the first argument.
The shebang line is usually ignored by the interpreter because the “#” character is a comment marker in many scripting languages; some language interpreters that do not use the hash mark to begin comments (such as Scheme) still may ignore the shebang line in recognition of its purpose.
Some typical shebang lines:
#!/bin/sh— Execute the file using sh, the Bourne shell, or a compatible shell
#!/bin/csh— Execute the file using csh, the C shell, or a compatible shell
#!/usr/bin/perl -T— Execute using Perl with the option for taint checks
#!/usr/bin/php— Execute the file using the PHP command line interpreter
#!/usr/bin/python -O— Execute using Python with optimizations to code
#!/usr/bin/ruby— Execute using Ruby
Shebang lines may include specific options that are passed to the interpreter (see the Perl example above). However, implementations vary in the parsing behavior of options; for portability, only one option should be specified (if any) without any embedded whitespace.
Go ahead, read more. It’s always fun to go back and have a little refresher isn’t it?