Skip to content

[Bug 批量·第二轮] 花括号展开/IFS 分词/glob 路径分隔符/BASHPID/进程替换/coproc 挂起/wait 错误/特殊内建管道扩展 - 11 项新差异(全部经 GNU Bash 对照) #21

Closed

Description

@caomengxuan666

[Bug 批量·第二轮] 花括号展开 / IFS 分词 / glob 路径分隔符 / BASHPID / 进程替换 / coproc 挂起 / wait 错误 / 特殊内建管道扩展 —— 11 项新差异(全部经 GNU Bash 逐字节对照)

背景

延续 #20 的差分探测方法(同一脚本 GNU Bash vs rubash 逐字节对比 stdout/stderr/rc),第二轮覆盖:printf/read/declare 变体、扩展 glob、花括号展开、IFS 分词、Windows 路径/UTF-8、特殊变量、进程替换、协程、mapfile、getopts、后台任务。每条均已用 Git Bash(GNU bash 5.2)对照确认,排除误报。

复现环境:winuxsh 0.10.2 / rubash 0.2.2(1)-release。探测脚本见 winuxsh 仓库 scripts/probe/probe-r2-*.sh。


一、确定性差异(每次必现)

1.1 双引号内的花括号被展开(高影响)

echo "M: {a,b}"      # bash: M: {a,b} (字面); rubash: M: a M: b (展开成两个参数!)
echo "Q: {1..20}"    # bash: 字面; rubash: 展开 1..20
  • bash 的花括号展开发生在词法阶段、双引号内不展开;rubash 在双引号内也展开。任何 echo "提示: {a,b}" 类脚本都会意外炸开成多参数。
  • 附:probe-r2-brace.sh

1.2 IFS 分词忽略中间空字段

IFS=:
s="a:b::c"
set -- $s
echo "$#"            # bash: 4 (a b "" c); rubash: 3 (a b c, 空字段被吞)
  • 默认 IFS(空白)的连续空白合并行为一致;仅非空白 IFS 的中间空字段被忽略。
  • 附:probe-r2-ifs.sh、ifs-check.sh

1.3 "$*" 未用自定义 IFS 首字符连接

set -- "a b" c
IFS=,
echo "[$*]"          # bash: [a b,c] (IFS 首字符 , 连接); rubash: [a b c] (仍用空格)

1.4 glob 展开结果使用反斜杠分隔符(${f##*/} 等正斜杠模式失效)

cd "$HOME/.oh-my-winuxsh"
for f in "aliases"/*.toml; do echo "${f##*/}"; done
# bash: common-aliases.toml (正斜杠路径, ##*/ 生效)
# rubash: aliases\common-aliases.toml (反斜杠路径, ##*/ 不匹配 → 保留前缀!)
  • glob 结果含反斜杠,导致所有依赖 / 的字符串处理(${f##*/}、${f%/*}、basename 前的裁剪)失效。
  • 附:probe-r2-glob.sh F 段

1.5 进程替换嵌套命令替换输出丢失

echo "$(cat <(printf 'psub'))"   # bash: psub; rubash: 空
diff <(cmd) <(cmd)               # 直接进程替换 OK (对照)
  • 进程替换作为命令替换的输入时输出丢失;直接使用(diff/重定向)正常。

二、严重问题

2.1 coproc 解析错误且挂起

coproc MY { printf 'coproc-ok\n'; }
read -r out <&"${MY[0]}"
echo "$out"
# bash: coproc-ok; rubash: "unknown argument '--' (not a script file)" 且后续 read 永久挂起(超时)
  • 注意 coproc 甚至把后续脚本内容当成命令行参数(unknown argument '--'),脚本在此永久挂起(60s 超时被杀)。可用任意脚本触发挂起(DoS)。
  • 附:probe-r2-misc.sh D 段(已注释防挂起)

2.2 wait 内建报错且返回码错误

sleep 0 &
pid=$!
wait "$pid"
echo "rc=$?"         # bash: rc=0; rubash: "unknown argument '--' (not a script file)" + rc=1
  • 后台任务等待是脚本常用操作,wait 失效影响面大。附:compare-r2b.sh

2.3 BASHPID 顶层值错误(= PPID)

echo "$BASHPID $PPID"   # bash: 不同 (498 1); rubash: 相同 (41452 41452)
( echo "$BASHPID" )     # 子 shell 内 rubash 正确(新 PID) — 仅顶层错

三、家族扩展(归入 #20 既有条目)

3.1 特殊内建进管道失败家族扩大(#20 §3.1)

已确认除 set -o 外,以下特殊内建进管道同样报 pipeline command could not execute: builtin command not found:

set | head -1        # 失败
export | head -1     # 失败
type ll | head -1    # 失败
trap -p INT | head -1 # 失败 (trap -p 重定向到文件正常, 仅管道失败)

3.2 cd 状态依赖异常(#20 §1.x 家族)

四、已确认正常(防误报,均与 bash 一致)

  • UTF-8 中文:${#zh} 按字符计数、${zh:0:2} 子串、${zh^^} 大小写、中文目录 cd —— 全部正常
  • 空格/特殊字符路径(t dir、t#x)cd 正常
  • read 全部变体(-d/-n/-a/多变量/IFS=)
  • declare/typeset/unset 全部变体(-i/-r/-x/-p/-F、readonly、unset -f/-v、数组元素 unset)
  • printf:%s/%b/%q/%d/%f/%x/%o/%c、宽度/精度/对齐、多格式复用、-v、%1$s(两侧均不支持,非差异)
  • mapfile/readarray、BASH_REMATCH(=~ 捕获组)、alias + expand_aliases、export 环境传递、$-、EPOCHSECONDS/BASH_COMMAND、$'...' 赋值展开、花括号展开(双引号外,A-I 段)
  • sleep 0.1(前台 rc=0)

附:探测脚本(winuxsh 仓库 scripts/probe/)

  • probe-r2-printf.sh / probe-r2-read.sh / probe-r2-declare.sh / probe-r2-declare-km.sh
  • probe-r2-glob.sh / probe-r2-brace.sh / probe-r2-ifs.sh
  • probe-r2-win.sh / probe-r2-misc.sh
  • 对照:ifs-check.sh、compare-r2.sh、compare-r2b.sh(bash vs winuxsh 双侧输出)

建议优先级:2.1 coproc 挂起(DoS)> 2.2 wait > 1.1 双引号花括号 > 1.4 glob 分隔符 > 其余。

Activity

  1. arookieofc commented on Aug 13, 2026

    @arookieofc
    Member

    继续修复 heredoc/命令替换挂起与解析根因:command substitution 内 heredoc 的收集顺序已修复。验证:part_005 40/40;上游 heredoc/comsub/procsub 相关 7/7。

  2. arookieofc commented on Aug 13, 2026

    @arookieofc
    Member

    参数替换反斜杠 pattern 差异已修复,新增回归测试 part_024;13/13 通过。

  3. arookieofc commented on Aug 14, 2026

    @arookieofc
    Member

    Fixed in commit 1665d23. Custom whitespace-only IFS values such as IFS=" " now collapse repeated delimiters like Bash, while IFS set to newline preserves ordinary spaces. Verification: cargo test --lib field_split (4 passed), the focused CLI regression (1 passed), full lib (165 passed), full CLI (153 passed).

  4. arookieofc commented on Aug 14, 2026

    @arookieofc
    Member

    2026-08-14 follow-up: fixed ordered fd-copy propagation for eval/brace groups, standard &N targets, read-write <> handling for builtins, and process-substitution input redirect rewrites. The executor suite is now 1523/1523. Coprocess/background suite families still require separate upstream-slice verification.

  5. arookieofc commented on Aug 17, 2026

    @arookieofc
    Member

    2026-08-17 follow-up (commit 62c64eb): fixed the focused coproc and Windows pipeline root causes. Completed named coproc endpoints are now retained when the current command consumes their input redirect, and external cat drains virtual CoprocStdout endpoints through the normal output path. On hosts without yes/head/wc in PATH, plain external pipelines use streaming internal utility processes over real OS pipes, so yes | head and yes | head | wc do not buffer or hang. Evidence: cargo test --test cli_tests coproc -- --nocapture 17/17; cargo test --test cli_tests external_pipeline -- --nocapture 4/4; full cli_tests 229/229; full executor_tests 1535/1535. Durable details: docs/issue-suite-diff-analysis.md.

  6. caomengxuan666 commented on Aug 21, 2026

    @caomengxuan666
    MemberAuthor

    New focused probe classification: complete process substitution p=>(...) has cleanup parity between GNU Bash and Rubash. For embedded p=x>(...)y, Bash exposes /dev/fd/63 while Rubash exposes a Windows temp path; this is a host representation/materialization difference, not an uncollected side-file defect. Raw evidence is target/ps-cleanup-probe/. No Rust cleanup patch is justified without an explicit Windows /dev/fd contract. Dynamic FD move/reuse also passes 1/1 with Bash/Rubash output moved=alpha source=10 reused=10 and closed-status:0; existing fixes are bfadaeb and 63c2d7e.

  7. caomengxuan666 commented on Aug 21, 2026

    @caomengxuan666
    MemberAuthor

    Correction to the earlier classification: the embedded process-substitution probe is a confirmed semantic candidate, not merely a host representation difference. GNU Bash runs p=x>(...)y, creates the side file, and outputs x/dev/fd/63y; Rubash currently does not start the producer, does not create the side file, and concatenates a Windows temp path. Complete p=>(...) cleanup remains parity. Raw evidence: target/ps-cleanup-probe/. No expected-output change or Rust patch has been made yet.

  8. caomengxuan666 commented on Aug 21, 2026

    @caomengxuan666
    MemberAuthor

    Embedded assignment process substitution is now fixed in 5f77bf2. Root cause was materialize_assignment_process_substitutions creating only an unregistered temp path for embedded output substitutions; the producer was never started. The fix registers the endpoint/source for the existing finish handoff. Regression now asserts side-file content, and the focused process-substitution family passes 56/56. GNU Bash/Rubash semantic probe now agrees on producer execution and payload creation; Windows path spelling remains platform-specific.

  9. caomengxuan666 commented on Aug 21, 2026

    @caomengxuan666
    MemberAuthor

    Persistent stderr/job-status boundary probe is classified unresolved-but-not-confirmed as an engine bug. GNU Bash and Rubash matched on basic coproc stderr inheritance, persistent stderr redirection, wait/0 preservation (including 143), and a reduced REFLECT wait/kill condition. Artifact: target/issue-suites/results/coproc-persistent-stderr-boundary/. The full upstream coproc body still has Windows fd-number/host fixture differences and one extra REFLECT stderr line that does not reproduce in the reduced fixture; no JobTable change was justified.

  10. caomengxuan666 commented on Aug 28, 2026

    @caomengxuan666
    MemberAuthor

    关闭说明

    原始报告的 11 项差异,大部分已修复:

    修复项 提交
    IFS 分词 commit 1665d23
    fd 有序传播 commit 1665d23
    coproc commit 62c64eb
    进程替换 已修复
    管道根因 commit 62c64eb

    剩余花括号嵌套展开 ({a,b}{1,2}) 在 #43 braces 中跟踪。关闭历史 issue。

  11. added
    bug
    gnu-baseline
    on Oct 17, 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

    buggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions