Skip to content

Function in a pipeline stage with an explicit redirect resolves as "command not found" #1823

Closed

Description

@caomengxuan666

现象

函数出现在管道中、且该函数 stage 带有显式重定向时,rubash 把函数名当作未找到的命令(rc=127)。无重定向的管道函数、非管道的重定向函数调用均正常。GNU bash 5.3.20 全形通过。

最小复现(主会话 2026-10-27 在当前 master 31004cd 上独立复核,确定性)

source <bats-core>/lib/bats-core/common.bash   # 定义 bats_prefix_lines_for_tap_output
printf 'ignored\n' | bats_prefix_lines_for_tap_output </tmp/trap-out.txt
# rubash: line 1: bats_prefix_lines_for_tap_output: command not found, rc=127
# GNU 5.3.20: # line1, rc=0

内联定义函数同形复现(主会话复核):

myf() { echo inner; }
printf "x\n" | myf </tmp/trap-out.txt
# rubash: myf: command not found, rc=127

收窄(#1720 复跑簇实测,GNU 全过)

形状 rubash
printf 'x' | f(函数唯一/末级,无显式重定向) 过
cat file | f(函数末级,管道 stdin) 过
printf 'x' | f | cat(函数居中,管道 stdin) 过
f <file(无管道,显式重定向) 过
f <file | cat(函数非末级 + 显式重定向) command not found
f <file | g(双函数 + 显式重定向) command not found
printf | f <file(函数末级 + 显式重定向) command not found
EXIT trap 内 f <file | g >&3 / 内联定义函数同形 command not found

精确触发条件:函数出现在管道中且该 stage 带有显式重定向。 位置(首/中/末)、trap 内外、定义方式(source/内联)均不影响触发。疑似面:含显式重定向的管道 stage 在命令名解析时旁路了函数表(待修复簇以 GNU C 源码 / 执行器面定性)。

实际影响

bats-core 的 bats_exit_trap 每条测试退出时执行 bats_prefix_lines_for_tap_output <"$BATS_OUT" | bats_replace_filename >&3,正中此形——bats 场景链因此每条 not ok(formatter 本身坏掉,体内成败不可观测)。这是 #1720 复跑中露出的新根,与 #1720 原症状(0 执行,已随 #1810 的 #1703 修复消失)不同根。

附带观察(同案内记,不另立案)

trap 内函数调用报错时行号误指定义行:bats-exec-test 报错 line 113(bats_exit_trap() { 定义行),真实调用在 193 行。修复时顺手核对报错行号归属。

归宿与验收

归宿:pipeline/fd 修复簇(与 #1820/#1822 同域,是否同批由主会话定)。验收 = 上述复现形与 GNU 同形输出,且 #1720 的 bats 场景链 3/3 + 2/2 全过(formatter 修好前体内成败不可观测,终验只认场景链全过)。

证据:~/workspace/rubash-fix6/clusters/1720-rerun/REPORT.md(复跑簇报告;#1720 保持 open 作场景链跟踪)。

Activity

  1. added
    bug
    gnu-baseline
    on Oct 27, 2026
  2. added
    P1-high
    area:parser
    family:S3
    on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P1-higharea:parserbugfamily:S3gnu-baseline

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions