Skip to content

[bug] $0/BASH_SOURCE of a script invoked by absolute /d/-style path is rewritten to D:/ native form while $PWD stays /d/ — breaks path math (bats-core suite blocked) #224

Closed

Description

@caomengxuan666

Found via bats-core self-suite entry-chain work (ecosuite lane; bats-core @ 52439ebfac39987dd43e26502aa4aa19f2753d4).

Minimal reproducer (WSL GNU Bash 5.3.0 = oracle)

pwdsrc.sh (executable script):

#!/usr/bin/env bash
echo "PWD=$PWD"
echo "BASH_SOURCE=${BASH_SOURCE[0]}"
echo "ZERO=$0"

Invoke with an absolute POSIX-style path: rubash.exe /d/repo/.../pwdsrc.sh

  • GNU bash 5.3.0 (bash /mnt/d/.../pwdsrc.sh): all three are the SAME string the caller used; GNU never rewrites $0/BASH_SOURCE into a different path form. $PWD and $0 are always consistent.
  • rubash (worktree 9bf2df9):
    • PWD=/d/repo/rubash-wt-ecosuite (MSYS form)
    • BASH_SOURCE=D:/repo/rubash-wt-ecosuite/target/ecosuite/probe/pwdsrc.sh (native drive form)
    • ZERO=D:/repo/... (native drive form)

Relative invocation (rubash pwdsrc.sh from its dir) keeps the relative form (consistent with GNU), so the rewrite happens only for absolute /d/-style invocations (including exec /d/.../script).

Why it matters (bats-core blocked on it)

bats-core's launcher chain does cd "$(dirname "$(bats_readlinkf "${BASH_SOURCE[0]}")")" (libexec/bats-core/bats:120) and builds $BATS_RUN_TMPDIR/${BATS_TEST_FILE_NUMBER}-${BATS_TEST_FILENAME##*/}.src (lib/bats-core/preprocessing.bash:6). With $BASH_SOURCE in D:/ form, ${BATS_TEST_FILENAME##*/} does not strip (no / in backslash paths), producing the invalid mixed filename C:/Users/.../Temp/bats-run-XXX/1-D:\repo\...\tagging.bats.src -> Invalid argument, and every bats test file dies with not ok 1 bats-gather-tests (rc=1) while the same files are green under GNU (and on a patched copy with a D:/-normalizing readlinkf, GNU stays green, rubash still hits it from the second path source).

GNU C source: bash sets $0 from the filename as given to execute_disk_command/shell startup (shell.c); there is no platform re-canonicalization of $0/BASH_SOURCE independent of $PWD. The invariant rubash breaks: within one process, $PWD, $0, and BASH_SOURCE must live in the SAME path domain so dirname/parameter-chops compose.

Related: rubash#166 ($0 correctness family, content-level) — this issue is the path-FORM inconsistency (D:/ vs /d/) against $PWD after it.

Artifacts: target/issue-suites/results/ecosuite/bats-core/ (tagging.rub.err with the 1-D:\...src failure, GNU-green outputs), probe target/ecosuite/probe/pwdsrc.sh.

Also observed in the same chain (env-bound, winuxsh): export -f function does not survive exec env VAR=x <bash-script> under rubash (rubash exports BASH_FUNC_f%%=... correctly and direct rubash children import it; through the external env utility the function is lost — bin/bats:89-90 export -f bats_readlinkf + exec env BATS_ROOT=... bats reports bats_readlinkf: command not found at libexec/bats-core/bats:119). GNU env passes it through. That loss point is the external env tool, not the rubash engine.

Lane: wt4/ecosuite evaluation suites (no src/ fixes in lane).

Activity

  1. added 2 commits that reference this issue on Sep 27, 2026
  2. caomengxuan666 commented on Sep 27, 2026

    @caomengxuan666
    MemberAuthor

    已修复并合入 master(commit d3e8aff,lane wt4/ecofix,GNU 引用见提交;探针/夹具与 WSL GNU 5.3.0 字节一致)。感谢报告!

  3. added 7 commits that reference this issue on Sep 29, 2026
  4. added
    bug
    area:path
    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:pathbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions