-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Summary of the new feature / enhancement
Up to PowerShell 7.1.x, pwsh -File someScriptWithoutExtension - which works on Unix to this day - also worked on Windows (whereas the by-definition Windows-only Windows PowerShell always required -File arguments to have extension .ps1).
In PS 7.2, this was reverted with a stated rationale of, "[...] Windows doesn't support shebang, so we should be consistent with Windows PowerShell and only allow for scripts with .ps1 extension."
Allowing extension-less script-file names is crucial for properly supporting stand-alone, directly executable PowerShell scripts using a shebang line on Unix, such as #!/usr/bin/env pwsh
However, even on Windows this can be important, namely in mixed environments such as Git Bash:
In order to be able to use PowerShell to implement Git hook scripts, which are shebang-line based and all have extension-less names (e.g., pre-commit), pwsh.exe's (positionally implied) -File parameter would have to accept extension-less script paths (which it did until 7.1.x)
Please consider reverting the above-mentioned change (which again would allow not only extension-less files but files with any extension, as currently implemented on Unix platforms), given the following:
-
Git is a widely used tool, so facilitating direct PowerShell use is desirable (the alternatives / workarounds, show in this Stack Overflow answer, are suboptimal); the popularity of this Stack Overflow post shows there's significant community interest.
-
Retaining strict consistency with Windows PowerShell doesn't seem important in this case: backward compatibility is ensured (passing script paths with
.ps1extensions will continue to work); it is a merely a new capability that is added. -
Windows PowerShell's restrictive behavior was arguably never a good idea to begin with: users can be expected to know that only files containing PowerShell code can be passed to
pwsh -File, irrespective of the file's extension, as modeled by all major POSIX-compatible shells; e.g.bash somefile.withrandomextensionworks just fine, as long as said file contains Bash code.
Proposed technical implementation details (optional)
No response