I am using pyenv-win and discovered that in my Windows version (20H2 19042.1165), where.exe
supports scripts with shebang:
C:\> where python
C:\Users\ded\.pyenv\pyenv-win\shims\python
C:\Users\ded\.pyenv\pyenv-win\shims\python.bat
First python file is:
#!/bin/sh
pyenv exec $(basename "$0") "$@"
What is the magic? Is is native shebang support in where.exe
? Which Windows version include this feature?
PS: Running python
in a cmd
will execute python.bat
not python
.
where.exe
is finding a file in the path with the name you specified. If there is no extension, it also tries all extensions listed in the PATHEXT
environment variable. Your file doesn't need a shebang to be found.
Below creates a few text files and where
finds the no-extension one as well as the one with an extension listed in PATHEXT
:
C:>set pathext
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.py;.pyw
C:>echo >abc
C:>echo >abc.txt
C:>echo >abc.bat
C:>where abc
C:\abc
C:\abc.bat