1

what is the default shebang is none is specified in a python script, Like below.

print "hello world"
The Archetypal Paul
  • 41,321
  • 20
  • 104
  • 134
andy
  • 3,951
  • 9
  • 29
  • 40

1 Answers1

7

There is no default shebang.

A shebang is not Python syntax, it is a hint used by your shell on Unix (-like) systems, to find an appropriate executable to run the script with if found in the first line and the file is executable. If the line is missing, execution usually fails as the shell may try and execute the file as shell commands instead.

Some operating systems (specifically Windows) have different mechanisms in place to find the executable. For example, they can map the filename extension to the executable. In such cases any shebang lines are ignored.

See Shebang (Unix) on Wikipedia, and the Python Windows FAQ for further details. Python 3 has some improved Windows execution support, see Using Python on Windows; the py launcher will actually read shebang lines in to dispatch to the right Python interpreter.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • 2
    Execution does not necessarily fail. Assuming the file is executable in bash, the file will be interpreted as shell and each line will be executed as if it were a simple shell script – Necrolyte2 Jan 06 '15 at 14:43
  • [Related: Bash script execution with and without shebang](http://stackoverflow.com/questions/7268437/bash-script-execution-with-and-without-shebang-in-linux-and-bsd) – kojiro Jan 06 '15 at 14:44
  • @Necrolyte2: right, amended this. But it depends on the specific shell if they'll actually try to do this. – Martijn Pieters Jan 06 '15 at 14:44
  • @kojiro: exactly; how the shell behaves when faced with a file without a shebang is dependent on the exact shell. :-) But I suspect the OP is using Windows, hence the Windows-specific info. – Martijn Pieters Jan 06 '15 at 14:46
  • The probability of an arbitrary Python script also being a valid bash script that does anything desirable is pretty low :) Although if you count "outputs a bunch of bash error messages" as a "successful execution" then your chances are much better ;) – Karl Knechtel Jan 06 '15 at 14:58