Shebang doesn’t work with python3

Generally, take care of some pitfalls: set the executable flag on the script: chmod u+x test.py try to execute with a preceding dot “./”, so call ./test.py otherwise it might execute some other script from within your PATH also make sure you don’t have windows line endings, this seems to prevent the shebang evaluation, too. There are some suggestions around, e.g. in this answer, on … Read more

What does the line “#!/bin/sh” mean in a UNIX shell script?

It’s called a shebang, and tells the parent shell which interpreter should be used to execute the script. Most scripting languages tend to interpret a line starting with # as comment and will ignore the following !/usr/bin/whatever portion, which might otherwise cause a syntax error in the interpreted language.

Proper shebang for Python script

is more portable because in general the program /usr/bin/env can be used to “activate” the desired command without full path. Otherwise, you would have to specify the full path of the Python interpreter, which can vary. So no matter if the Python interpreter was in /usr/bin/python or in /usr/local/bin/python or in your home directory, using #!/usr/bin/env python will work.