What does it mean in linux scripts? #!/usr/bin/python -tt What does it mean in linux scripts? #!/usr/bin/python -tt bash bash

What does it mean in linux scripts? #!/usr/bin/python -tt


Question #1) The line is called a shebang, and there's no right form that works universally. e.g.

#!python#!/usr/bin/python#!/usr/local/bin/python#!/usr/bin/python -t

are all valid/acceptable forms, but may not work on all systems:

#!python will work only if the python executable is somewhere in your shell's PATH

#!/usr/bin/python only works if the python binary is actually in /usr/bin

#!/usr/local/bin/python also only works if python is in /usr/local/bin

Question #2)

#!/usr/bin/python -tt is passing the -tt option to python, as if you'd done:

$ python -t somescript.py

at the shell prompt. You can pass arbitary command line arguments to the interpreter on the shebang line.

Question #3)

The line is interpreted by the OS kernel and the shell you're currently using. The stuff after the #! simply tells the OS which program should be fired up to "execute" the rest of the script.

Question #4)

The script syntax depends on the language you're using. E.g. a PHP shell script must take the form of

#!/usr/bin/php<?php  ... php code here ...

A #!/usr/bin/perl perl script must use Perl syntax, etc... If you put PHP code with a Perl shebang, you'll just have Perl barf up the script with syntax errors, as PHP code is NOT perl code

Question #5)

Shebangs are for Unix systems, where file extensions were never really used to identify file types to the OS. A .c file was understood to be a C language source code file, but that's merely a convention. You could put a Bash shell script into a .c file, make it executable, and with the #!/bin/bash shebang, it would execute as a Bash script.

Determining executable types by file extension is more of a Windows thing.

Question #6)

That goes back the stuff in question #1 - if the shebang claims the interpreter is at some OTHER path than where it is, this particular script can't be executed until the shebang is fixed, or the interpreter is moved. Shebangs are very handy, but not infallible.

Thankfully, most interpreters are installed in fairly standard locations these days, so it'd be somewhat unusual to find (say) Perl installed at /some/wonky/weird/path instead of /usr/bin


From the manpage:

-t Issue a warning when a source file mixes tabs and spaces for indentation in a way that makes it depend on the worth of a tab expressed in spaces. Issue an error when the option is given twice.

  1. The right form of the line is the one you want to use.
  2. It's the interpreter that reads this line known as shebang. If you write a python script with first line as "#!/usr/bin/python" & invoke it using bash, it's the /bin/sh interpreter that reads first line and starts the proper interpreter.
  3. It's a shebang. The syntax of feature consists of the character sequence #!, i.e. the number sign and an exclamation point character
  4. File extensions are not relevant in linux generally. You can have a python script that doesn't have a .py extension.

For ex.

shadyabhi@archlinux ~ $ cat a print "Hello World" shadyabhi@archlinux ~ $ python2 a Hello World shadyabhi@archlinux ~ $

Even the shebangs are only necessary if you want to start a script using $./script as in this case you didn't mention the interpreter you want to use.


  1. #!/usr/bin/env python
  2. issue errors about inconsistent tab usage
  3. Kernel
  4. #!/path_to_the_interpreter or /usr/bin/env
  5. *nix does not check extensinon at all(except some DE could do that)
  6. This is why you should use #!/usr/bin/env

More info at wiki