Cannot pass an argument to python with "#!/usr/bin/env python" Cannot pass an argument to python with "#!/usr/bin/env python" python python

Cannot pass an argument to python with "#!/usr/bin/env python"


In some environment, env doesn't split arguments.So your env is looking for python -u in your path.We can use sh to work around.Replace your shebang with the following code lines and everything will be fine.

#!/bin/sh''''exec python -u -- "$0" ${1+"$@"} # '''# vi: syntax=python

p.s. we need not worry about the path to sh, right?


It is better to use environment variable to enable this. See python doc : http://docs.python.org/2/using/cmdline.html

for your case:

export PYTHONUNBUFFERED=1script.py


This might be a little bit outdated but env(1) manual tells one can use '-S' for that case

#!/usr/bin/env -S python -u

It seems to work pretty good on FreeBSD.