Skip to content

[bug] P0 herestring 任何参数展开为空内容: read x <<< "${v#--}" 全灭(makepkg parseopts 长选项全崩为 option '--' is ambiguous) #165

Closed

Description

@caomengxuan666

现象

herestring (<<<) 的内容如果是参数展开(${...} 任何形式),rubash 侧内容为空;纯字面量与裸 $var 正常;同内容 heredoc 正常。GNU Bash 5.3.0 全部正常。

生产杀伤:pacman makepkg 7.x 的 libmakepkg/util/parseopts.sh 用 IFS='=' read -r opt optarg <<< "${1#--}" 解析全部长选项 → rubash 下 opt 恒空 → 前缀匹配命中所有长选项 → --version/--help/--printsrcinfo 全部报 option '--' is ambiguous 退出,makepkg 完全不可用。

最小复现

probe-hs.sh(LF 落盘,双侧脚本文件运行):

x=--version
y=alpha
read -r v1 <<< "$x"
echo "1 plain-var: [$v1]"
read -r v2 <<< "${x#--}"
echo "2 strip-hashhash: [$v2]"
read -r v3 <<< "${x:2}"
echo "4 substring: [$v4]"
read -r v5 <<< "${x^^}"
echo "5 upper: [$v5]"
read -r v6 <<< "${y/a/b}"
echo "6 replace: [$v6]"
read -r v10 <<< "literal"
echo "10 literal: [$v10]"
read -r v11 <<EOF
${x#--}
EOF
echo "11 heredoc-expand: [$v11]"
case GNU 5.3.0 rubash 8f89767
1 <<< "$x" --version --version
2 <<< "${x#--}" version 空
4 <<< "${x:2}" version 空
5 <<< "${x^^}" --VERSION 空
6 <<< "${y/a/b}" blpha 空
10 <<< "literal" literal literal
11 heredoc <<EOF + 展开 version version

IFS 变体同样死: IFS='=' read -r a b <<< "${x#--}" → GNU a=version; rubash a=空 b=空(probe-read.sh case I)。

makepkg 现场

makepkg.sh --version 在 rubash 下输出:

D:epo ubash arget-ecosys6\makepkg-render\makepkg.sh: option '--' is ambiguous; possibilities: 'allsource' 'check' ... 'version'

(前缀乱码是另一个 $0 bug,见后续 issue;'--' 即本 bug:opt 为空导致 0 长前缀匹配所有长选项。)

定位建议

herestring word 的展开结果未被写入 herestring 临时文件/管道(字面量与裸变量路径正常),或展开在 herestring 上下文被提前剥掉。对照 GNU: redir.c herestring 构造走 redir_expand → word 展开(subst.c expand_word)后写临时文件。

版本: rubash 8f89767 (target-wire/debug), 对照 WSL GNU Bash 5.3.0(1)-release。
产物: D:/repo/rubash/target-ecosys6/out/{hsprobe.gnu.out,hsprobe.rub.out,readprobe.*,makepkg.diff}

Activity

  1. caomengxuan666 commented on Sep 26, 2026

    @caomengxuan666
    MemberAuthor

    已在 master 29714d5 修复(wt/m1-here @ c5be754 全量验证)

    L-I 车道的 WORD_DESC 引号分段修复(29714d5e,expand_here_string_segments 一族,redir.c:373 r_reading_string 对应)已顺带修掉本单的根因——herestring 操作数改走 raw word 分段展开 + 最终 carrier decode,参数展开不再被剥空。

    在 wt/m1-here(基线 c5be754 = 29714d5 之后,产物 target/m1/)复核:

    • 30 形态矩阵(hs-matrix.sh:dquote/无引号/单引号 × ${v#--}/${v:2}/${v^^}/${v/a/b}/${#v}/${v:-def}/嵌套 ${x#${x%%v*}}/comsub/拼接/含空白值/$*/$@/多行 × read/IFS=read/赋值目标)与 WSL GNU Bash 5.3.0 逐字节一致。
    • C3 probe-read.sh(含 makepkg 现场 IFS='=' read -r opt optarg <<< "${x#--}" 的 I 形态)双侧一致。
    • makepkg 探针(C3 产物 fixture 复刻运行):--version 打出版本横幅、--help、--printsrcinfo、--packagelist 全部被识别,不再出现 option '--' is ambiguous;剩余 diff 仅 --help 文本渲染(n 换行丢失 + Usage 行 $0 路径 = [bug] P0 脚本内执行脚本: 子脚本 $0 错误(fork 形态继承父 $0 / exec 形态 .\反斜杠路径),${0##*/} 自定位全家崩 #166 家族)。

    建议:关闭本单时在 29714d5 上加 backlink;#166($0)解锁后 makepkg-drive 可全量对齐。

  2. caomengxuan666 commented on Sep 26, 2026

    @caomengxuan666
    MemberAuthor

    已随 L-I 车道的 herestring 修复(29714d5e,expand_here_string_segments 的 raw 分段展开+载体解码)在 master 上生效——M1 车道复核确认无需新代码:30 形态矩阵(引号上下文 × ${v#--}/${v:2}/${v^^}/${v//}/${#v}/默认值/嵌套/comsub/$*/$@/空白值 × read/IFS-read/赋值目标)与 WSL GNU 5.3.0 字节一致;C3 probe-read 一致;makepkg parseopts 探针通过(--version/--help/--printsrcinfo/--packagelist 全识别,'option -- is ambiguous' 消失;残余 --help 差异属 $0/#166 家族)。

  3. added
    bug
    P0-critical
    area:parser
    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

    P0-criticalarea:parserbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions