已关闭
[Bug-Report|缺陷反馈]: init.sh 在旧版本 bash 下因 heredoc 与命令替换同行闭合写法报 syntax error(trae 分支) #608
jiangyixuan2创建于 13 天前关闭于 11 天前
13 天前 添加了label:bug-report
13 天前 issue类型由 任务 改变为 缺陷
13 天前 关联了pull request:test(init): 行为测试新增 bash 解析诊断负向断言,看护 init.sh 旧版 bash 兼容性
11 天前 关闭了 issue
11 天前 添加了label:resolved


一、问题描述(必填)
plugins-official/ops-direct-invoke/init.sh(732 行)与plugins-community/cuda2ascend/init.sh(737 行)的 trae 分支使用了如下写法——命令替换的闭合)与 heredoc 起始符写在同一行:agent_count=$(TRAE_AGENT_OUT="..." python3 - ... << 'TRAE_AGENT_PY' 2>/dev/null) import os, re, sys ... TRAE_AGENT_PY在旧版本 bash 下直接安装失败:
报错行 736 是 heredoc 内的 Python 代码,根因在 732 行:旧版 bash 解析时丢弃未完成的 heredoc,Python 正文被当作 shell 命令逐行解析,
os.makedirs(out_dir,被误判为函数定义导致语法错误。新版 bash(实测 5.2.21)对该写法仅输出警告且功能正常:
warning: command substitution: 1 unterminated here-document(退出码 0、产物齐全),因此开发与 CI 环境未暴露。引入提交(git log -S 定位):
二、环境信息
三、重现步骤
bash plugins-official/ops-direct-invoke/init.sh(任意 tool 参数)syntax error near unexpected token 'out_dir,',安装中断bash -n init.sh输出warning: command substitution: 1 unterminated here-document四、预期结果
init.sh 使用 POSIX 规范写法(
)置于 heredoc 终止符之后),在所有受支持环境的 bash 版本下正常解析执行。💡 备注
)从 heredoc 起始行移到终止符TRAE_AGENT_PY之后(仓库内其余 20+ 处 heredoc 均为规范写法,仅这两处特殊),逻辑零变化tests/behavior/install/test-init-behavior.sh有 8 个 trae 场景真实执行了该代码路径,但断言全部为正向(退出码 0 / 产物存在 / 期望文案),未检查 stderr 中的 bash 警告;建议补充「输出不含 warning」的负向断言 + init.sh 的bash -n语法门禁,实现版本无关看护