Skip to content

[Bug] 在win11 powershell 7 下执行ls env:查看环境变量报错 #1063

Closed

Description

@c00134744

Operating system / 操作系统

Windows

OS version and display / 系统版本与显示

Windows 11 Pro 23H2(build 22631)

Pebrel version / 版本号

2.6.0 (5ff71de)

How did you install Pebrel? / 安装方式

GitHub Release (.exe / .zip / .dmg / .AppImage / .deb)

Shell in the affected pane / 出问题的面板用的 Shell

PowerShell 7 (pwsh)

Program running in the pane / 面板里正在跑的程序

Nothing, plain shell prompt / 什么都没跑

Connection type / 连接方式

Local terminal / 本地终端

Affected area / 影响范围

Shell startup / PATH / start directory / context menu — Shell 启动、环境变量、起始目录、右键菜单

Did it work in a previous version? / 旧版本是否正常?

Not sure / 不确定

Can you reproduce it? / 复现概率

Always (100%) / 必现

Steps to reproduce / 复现步骤

  1. 启动 Pebrel,新开 PowerShell 7 标签页
  2. 执行 ls env:
  3. 每个环境变量报一条 InvalidOperation

❯ ls env:
InvalidOperation: ...\pebrel-shell\2.6.0-9b9c4248...\pebrel_prompt.ps1:363
363 | $date = '{0,12}' -f $i.LastWriteTime.ToString('MMM d HH:mm', …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 不能对值为 Null 的表达式调用方法。
-rw-r--r-- 1 all_proxy
...

改过的设置

follow_system_theme=0、shell=pwsh、refresh_environment=1;builtin_ls 未设置,保持默认 1。

补充观察:先执行一次 pwsh 就不报错

报错来自 Pebrel 启动时注入的脚本(启动参数 -Command ". '<temp>\pebrel_prompt.ps1'"),预先手敲执行的 pwsh 子会话不加载它,ls 退回原生别名:

场景 (Get-Command ls).Definition ls env: 错误数
加载了集成脚本的会话 Nebula-List 109
手敲 pwsh 起的子会话 Get-ChildItem 0
父会话内先启动并退出一个 pwsh 仍 Nebula-List 仍 109

即只有"在子会话里执行"才正常。

Expected behavior / 期望结果

ls env:
Name Value


xxx yyy

Actual behavior / 实际结果

❯ ls env:
InvalidOperation: ...\pebrel-shell\2.6.0-9b9c4248...\pebrel_prompt.ps1:363
363 | $date = '{0,12}' -f $i.LastWriteTime.ToString('MMM d HH:mm', …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 不能对值为 Null 的表达式调用方法。
-rw-r--r-- 1 all_proxy
...

Logs / screenshots / 日志或截图

图片

Non-default settings / 改过的设置

follow_system_theme=0、shell=pwsh、refresh_environment=1;builtin_ls 未设置,保持默认 1。

Before submitting / 提交前确认

  • I searched existing issues and did not find a duplicate / 已搜索,无重复
  • I tested with the latest release / 已用最新版本试过
  • I removed passwords, private keys, tokens and other secrets / 已删除敏感信息

Activity

  1. added
    bug缺陷:行为与预期不符 / something isn't working
    triage待维护者初审 / not yet reviewed
    on Nov 20, 2026
  2. added
    area: shellShell 启动、profile、环境变量/PATH、起始目录、资源管理器右键
    os: windows仅 Windows 或与 ConPTY/Win32 相关
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: shellShell 启动、profile、环境变量/PATH、起始目录、资源管理器右键bug缺陷:行为与预期不符 / something isn't workingos: windows仅 Windows 或与 ConPTY/Win32 相关triage待维护者初审 / not yet reviewed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions