Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have seen many files which have this line as the first line in them. What exactly is this?

#!/usr/bin/env python

What does it mean? Why is it necessary?

share|improve this question
The mechanism behind this construct can be found in the execve man page. – glenn jackman May 6 '14 at 20:02
Welcome to Ask Ubuntu. Please, could you put some of your time to read What should I do when someone answers my question? – Sylvain Pineau May 12 '14 at 11:13

It's not just /usr/bin/env python but #!/usr/bin/env python and this line is called a shebang.

I'm quoting Wikipedia:

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.[8] 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.

In my case (13.10 Desktop), /usr/bin/env python will default to python2.7 but it could be python3.4 depending on your system defaults (e.g. 14.04 Server).

$ /usr/bin/env python
Python 2.7.5+ (default, Feb 27 2014, 19:37:08) 
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
share|improve this answer
That means hashbang will be used to tell the program loader that python interpreter is to be called when a script will be run? But, when I create python files, I never put this hasbang on the top. But still that file executes normally. then, what is it? Explain please. – hellodear May 5 '14 at 9:34
You only need the shebang line if you want your python script to be run like this: ./ Without the shebang, you'll have to call python to interpret the script: python ./ – Sylvain Pineau May 5 '14 at 9:50
@SylvainPineau When running a script residing in the current directory by passing it as a command-line argument to the interpreter, there's no need to precede it's name with ./. python works just as well. (It's specifically when a script equipped with a functioning hashbang/shebang line--or other executable--is run as a command in its own right, with its name as the first word on the command line, that ./ is useful.) – Eliah Kagan Aug 4 '14 at 2:27

A line like this can appear on the first line of interpreted programs or scripts. It is a directive to the program loader to pass the file to the interpreter - in this case Python.

Interpreter directives are placed on the first line of an executable script after the characters #! (called a shebang or hashbang) so that a script can be executed by just the script name, in one of the following ways from the command line:

$ script
$ ./script
$ path/to/script

To be able to execute the script in this way like a command, it must have execute permission.

instead of the interpreter with the script name as an argument which would be required if the interpreter directive was not there, like thus:

$ python path/to/script
share|improve this answer
What can be the "path/to/script" ? I mean how can I find it? What is it at your system so that I can get an idea. Thanks. – hellodear May 5 '14 at 9:39
By "path/to/script" I mean the relative or absolute pathname to the script that you are trying to execute. For example, if I am in my home directory and I want to run in the scripts directory in my home directory then the relative pathname would be scripts/ – jamtin May 5 '14 at 11:15

#! is called shebang. Normally, Bash considers the symbol # as a comment, however upon seeing #! Bash knows that the rest of the content should be a script and the first line will refer to which program or interpreter to invoke. In the case of #!/usr/bin/env python Bash knows that this line is invoking the correct "environment settings" for the Python interpreter. Thus the rest of the file's content will be run using the Python interpreter. Had the line been like #!/bin/bash or #!/usr/bin/perl Bash would have run the content using Bash (itself) or Perl respectively.

You can still write a Python, Bash or Perl script without mentioning this line. In that case to run your Python script you'd need to invoke from command line this way:


This is because without shebang #! and without a correct interpreter path, Bash would not know it's a script and would treat it as a text file.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.