When you double-click a .sh
in Windows, Git Bash actually launches it via a wrapper (sh.exe
or bash.exe -c …
) rather than executing it directly. That wrapper injects extra frames (MSYS2 startup, the “–c” eval, etc.) into the call stack, so your hard-coded
bash
CopyEdit
caller_file="${BASH_SOURCE[2]}" caller_line="${BASH_LINENO[1]}"
no longer point at the TestFunction "11111" "22222"
line (28) but at the very first source
in your script (line 6) .
Open Git Bash and do:
bash
CopyEdit
./tester_copy.sh
This invokes bash.exe
directly on your script (no wrapper), so the call stack is exactly
css
CopyEdit
ErrorReport → TestFunction → Main
and ${BASH_SOURCE[2]}
→ tester_copy.sh
, ${BASH_LINENO[1]}
→ 28 as you expect .