Back in the beginning of time there was an issue dealing with the way powershell handles (executable) script files, most often seen in anything made in a native *nix environment. The idea is to be able to run hashbanged scripts from pwsh.
Q: What is a hashbanged script?
A: Pretty much any script starting with something like:
#!/usr/bin/env python3
# mypyscript -- This is any random python coded script executable from command line
print('Don't let hashbang issues disappear like teardrops in the sea!')
...
Yes, so you noticed this hashbang is not for windows. Well, yes a no. It is correct for WSL, but powershell doesn't understand it for the obvious reason, it is supposed to be path. However, if Windows powershell would like to maintain any compatibility with any future script handling, pwsh developers need to rethink this "path": /usr/bin/env and handle it as a virtual path like any of the other special windows paths.
Two things for sure.
#!python3, but maintaining full compatibility with the 20+ year /usr/bin/env and /bin/<interpreter> formats. ./mypyscript
# doesn't work
./mypyscript
Don't let hashbang issues disappear like teardrops in the sea!
We should be able to dot-execute any scripted code from powershell command line, when that code contain the correct hashbang for the scripting engine. (Eg. .ps1 .py .go .js etc.)
Doesn't work:
Opens a window dialog, asking what you want to use to open this file.
A secondary issue, is that:
some installers actually modify the original code's first hashbang line.
This should never be allowed to happen!
A longer and far more technical and detailed discussion of this, was made in this issue:
But it's title is perhaps not ideal, to make it a very relevant issue, although it is the essence.
(Issue pertains to handling of . (dot) in the $env:PATHEXT. )
Furthermore there was an honest attempt by @mklement0 to provide a CMD-based work-around
as discussed in this SO question:
IIRC shebangs/hashbangs are really handled in the kernel and not the shell and the Win32 subsystem on the NT kernel doesn't have a concept of shebangs. For non-executable files, Windows really uses the extension of the file to determine what program to use to open the file itself so when you do ./mypyscript with a shebang of #!/usr/bin/env python3 Windows has no idea what to do with it. Even trying to add support for interpreting Unix shebangs will be fraught with danger and IMO too magical, using #!/usr/bin/env python3 as an example:
python.exe so there will be no python3.exe in the PATH#!/usr/bin/python3 then it's the same issue, probably even more so because it's a hardcoded path and on Unix it won't rely on the PATHPersonally I think this would require too much magic and maintenance to achieve.
Most helpful comment
IIRC shebangs/hashbangs are really handled in the kernel and not the shell and the Win32 subsystem on the NT kernel doesn't have a concept of shebangs. For non-executable files, Windows really uses the extension of the file to determine what program to use to open the file itself so when you do
./mypyscriptwith a shebang of#!/usr/bin/env python3Windows has no idea what to do with it. Even trying to add support for interpreting Unix shebangs will be fraught with danger and IMO too magical, using#!/usr/bin/env python3as an example:python.exeso there will be nopython3.exein thePATH#!/usr/bin/python3then it's the same issue, probably even more so because it's a hardcoded path and on Unix it won't rely on thePATHPersonally I think this would require too much magic and maintenance to achieve.