Skip to content

popd default pop changes the stack and PWD but does not chdir: 'pushd -n ./sub; popd' leaves the process cwd behind (GNU cds into ./sub) #830

Closed

Description

@caomengxuan666

发现渠道

#754 修复(PR #819)的 CR 复核在 pushd 栈形验证时的相邻观察:pre-existing,非该 PR 引入(master c6f4a9b:230/252/262 与 diff 逐字节相同)。

症状

pushd -n ./sub; popd:

  • GNU bash 5.3.0:栈弹出后 cd 进 ./sub(进程 cwd 变更)
  • rubash:栈与 PWD 变量已更新为 ./sub,但 进程 cwd 留在原目录(pwd 内建报新值,真实 cwd 未变)——pwd -P 与后续外部命令的工作目录暴露分歧

影响

依赖 popd 附带 chdir 的脚本(pushd/popd 目录轮换工作流的常见形态)在 rubash 下外部命令的工作目录与 shell 状态不一致。

验收

  • 对照 vendored bash(pushd.def/popd.c 的 chdir 时机)确认 GNU 语义
  • 修复:popd 默认弹出路径补 chdir(含失败诊断对齐 GNU)
  • 差分回归:pushd -n ./sub; popd; pwd -P(+外部命令 $(pwd))双 shell 对照
  • 注意与 dirs -c(清栈回落 cwd)路径的 chdir 语义一致性

Activity

  1. added
    bug
    P3-low
    area:builtins
    on Oct 18, 2026
  2. added a commit that references this issue on Oct 19, 2026
  3. caomengxuan666 commented on Oct 19, 2026

    @caomengxuan666
    MemberAuthor

    修复已落地:PR #837(合并 e32c0dd 之前身 5ca5c8a)——popd 顶弹按 GNU pushd.def:392-403 先 chdir 新栈顶(cd_to_string=cd_builtin)成功才弹栈+bindpwd 簿记;±N 经 resolved_index 归一(resolved==0 ⇔ 顶分支);chdir 失败报 popd: <词>: <strerror> rc 1 栈不动;空栈/越界文案对齐 pushd_error;popd 内层 cd 继承 POSIX 目录桥。CR 17 场景×三方矩阵全对齐(#837 评论)。后续边界另立:#844(readonly OLDPWD)、越界文案 args.last() 形(新票)。

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

    P3-lowarea:builtinsbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions