Whats the first line (#!) in shell scripts (also called as the sha-bang/shebang)

Todays unix flavors come with more than a kind of shell you can run your program with. While executing a shell script, the kernel has to know which one of these needs to be used to execute your script. The first line pretty much says that.
#! /bin/sh
 Is used to tell the kernel that this script needs to be executed using the /bin/sh (standard shell)
You can run this command to list out all the different shells in your machine
Sharaths-MacBook-Air:~ sharath$ cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells./bin/bash
The #! Is a general mechanism to invoke any programming language interpreter, not just the command shell.
#! /usr/bin/python
a = 1+1
print a
The above script executes the script in python.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s