I installed python2.7 and pyhton3.5 with apt-get.
In my .bashrc I have alias python=python3
to make python3 the default.
This works if I just run python directly, but it doesn't seem to work with /usr/bin/env.
How can I force python3 in this case?
$ python --version
Python 3.5.2
$ /usr/bin/env python --version
Python 2.7.12
Best Answer
That's because
env
is searchingpython
in yourPATH
, not on any shell builtin, or alias or function. As you have definedpython
aspython3
as an alias,env
won't find it, it will search throughPATH
and will resolvepython
to/usr/bin/python
(which ispython2
).You can check all the available locations of executable
python
, inbash
, do:You are out of luck if you want to use an alias in shebang as by definition, shebang needs to be an full path to the interpreter executable, which the
env
should resolvepython
to when you use/usr/bin/env python
. To interpret the script usingpython3
use the shebang: