Skip to content

[bug] 跨行 if (( ... || ... )) 报算术语法错误并取错分支(换行折叠为 ; 喂给求值器)——portage ebuild.sh:44 版本门禁即死,EAPI 机制无法进入 #174

Closed

Description

@caomengxuan666

现象

跨行的算术命令 (( ... ))(换行后以 || 续行)在 rubash 下报 arithmetic syntax error 并整体按假处理——条件求值结果错误 + 诊断泄漏。GNU Bash 5.3.0 正常跨行求值。$(( )) 赋值形式的同形跨行正常,只有 if (( )) 命令形式坏。

生产杀伤: portage 的 bin/ebuild.sh(~850 行 EAPI 处理入口)第 44 行 bash 版本门禁就是跨行 if (( BASH_VERSINFO[0] < maj\n\t\t|| (BASH_VERSINFO[0] == maj && BASH_VERSINFO[1] < min) )) ——rubash 直接死在门禁上,整个 ebuild 相位机制(~2k 行 EAPI 酷刑)无法进入。GNU 侧继续走到标准 die() 报错(PORTAGE_PYM_PATH does not exist),证明语义链完整。

最小复现

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

a=9 b=3 c=4 maj=5 min=3
if (( a > maj
		|| (a == maj && c < min) ))
then echo "lt-branch"; else echo "ge-branch"; fi
GNU 5.3.0 rubash 8f89767
stdout lt-branch ge-branch(错误分支)
stderr 空 `probe-arith2.sh: line 2: ((: a > maj;

注意错误 token 里的 maj; —— rubash 把换行折叠成了 ; 再喂给算术求值器(; 不是合法算术符)。而 $(( )) 赋值形式的跨行(v=$(( 1\n || 0 )) → 1、w=$(( 1 +\n 2 )) → 3)双侧一致正常(probe-arith.sh)。

ebuild.sh 现场

rub stderr: ./ebuild.sh: line 44: ((: BASH_VERSINFO[0] < maj;		|| (BASH_VERSINFO[0] == maj && BASH_VERSINFO[1] < min) : arithmetic syntax error ...
gnu stdout:  * ERROR: /:: failed (setup phase): PORTAGE_PYM_PATH does not exist ... (走完版本门禁后的正常 die)

源(portage bin/ebuild.sh:43-44):

if (( BASH_VERSINFO[0] < maj
		|| (BASH_VERSINFO[0] == maj && BASH_VERSINFO[1] < min) ))

定位建议

(( )) 命令的词法收集在换行处提前终止并把换行折为 ;;GNU 的算术命令读取直到匹配 ))(跨行合法)。对照 GNU expr parser: expr.c exprec()/read_token 在 arithmetic 上下文吃掉换行。

版本: rubash 8f89767 (target-wire/debug), 对照 WSL GNU Bash 5.3.0(1)-release。
产物: D:/repo/rubash/target-ecosys6/out/{arith.*,arith2.*,ebuild.*}

Activity

  1. caomengxuan666 commented on Sep 27, 2026

    @caomengxuan666
    MemberAuthor

    已在 51df49a 修复并关闭(commit 48089806,四单合一)。GNU 锚点与矩阵见 issue 评论区独立说明。

  2. added
    bug
    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

    area:parserbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions