PowerShell / PowerShell/PowerShell

Consistency of script execution in POSIX environments

未关闭
#27,205 16 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Issue-Enhancement Needs-Triage
主要语言
C#
星标
55.5k
派生
8.5k
平均合并
1 天 2 小时
30 天内合并 PR
88

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先追踪 PowerShell 如何在 PowerShell 进程内运行脚本,以及 POSIX shell 如何通过 exec 和 /usr/bin/env 调用可执行脚本。检查 access(X_OK) 所描述的可执行位行为;完成意味着可执行脚本使用 exec,而不可执行脚本保留现有处理方式。

由索引模型根据 Issue 内容生成。

评估

技术栈
shell
领域
cli, operating-systems
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。