The Shebang

As the first article, I decided to discuss the “Shebang“, also called many different ways: sha-bang, hashbang, pound-bang, or hash-pling.

In the UNIX world, there are scripts, in Linux for example, you will find a lot of “bash” scripts, when you edit one of these scripts there is a line at the top of the script, which looks something like:

#!/bin/bash

This line simply tells the shell, to use the interpreter specified in the shebang #!/bin/bash. In this particular case /bin/bash.

So, let’s say that you have a script called dosomething.bash, and the shebang is #!/bin/bash. To execute simple do:

./dosomething.bash

The shell will execute something similar to:

/bin/bash dosomething.bash

Of course any scripted language can have a shebang #!/usr/bin/perl or #!/usr/bin/python. You get the concept now, right?

Now, you ask, what if the shebang is not there and you execute the script? Let’s say that our script dosomething.bash does not have a shebang line.. you can still execute the script by forcing the interpreter:

/bin/bash dosomething.bash

Should you type ./dosomething.bash, the running shell will assume that the same shell is used, so, if you are running a bash session, life is good, but if you are running a ksh session, life could be bad…

Hope this article explains the shebang, have fun now in the UNIX world…

Well, that’s it, the mystical shebang is explained. Thanks for reading.

Leave a Reply