PowerShell / PowerShell/PowerShell
Consistency of script execution in POSIX environments
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 55.5k
- Forks
- 8.5k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 88
Description
Summary of the new feature / enhancement
Unlike standard Windows file systems, UNIX file systems support execution rights within the file attributes. This controls how the operating system executes a script or compiled binary.
PowerShell scripts can be marked as executable and can have the following prefix
#!/usr/bin/env pwsh
If the file is marked as executable then this can be run directly by any program using the exec system call.
If this is done with a PowerShell script then if it is run from a traditional shell then the exec system call will launch /usr/bin/env which in turn will identify how to run a pwsh and then launch pwsh and pass the name of the original script along with the remaining arguments.
If this same script is run from within the PowerShell process then no new process is launched and the script runs in the same process.
This means that the script may behave differently depending on how it was launched.
This proposal says that if the file that is to be run from PowerShell has the executable bit set, according to the equivalent rules of access(X_OK) then the program is launched with exec.
The end result is that if you want consistent POSIX style execution rights and protections then set the executable bit on the PowerShell script and include the hash-bang prefix.
Proposed technical implementation details (optional)
If the file that is to be run from PowerShell has the executable bit set, according to the equivalent rules of access(X_OK) then the program is launched with exec. If the executable bit is set no further examination of the file is needed, it will all be handled by exec.
If the file does not have the executable right set then the existing processing is done, in the case of a script it would be parsed and executed in the same process.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how PowerShell runs a script from within the PowerShell process and how POSIX shells invoke an executable script through exec and /usr/bin/env. Check the executable-bit behavior described with access(X_OK); done means executable scripts use exec while non-executable scripts retain the existing processing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- cli, operating-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100