Skip to content

fix(interpreter): populate BASH_SOURCE[0] for PATH-resolved scripts#1087

Merged
chaliy merged 1 commit intomainfrom
fix/issue-1085-bash-source-path-lookup
Apr 6, 2026
Merged

fix(interpreter): populate BASH_SOURCE[0] for PATH-resolved scripts#1087
chaliy merged 1 commit intomainfrom
fix/issue-1085-bash-source-path-lookup

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 6, 2026

Summary

  • When a script is executed via PATH lookup (by name, not by path), BASH_SOURCE[0] was empty because only the bare command name was passed to execute_script_content() instead of the resolved path
  • Fixed try_execute_script_via_path_search() to pass the fully resolved candidate path
  • Added 2 new tests: direct BASH_SOURCE check and source-guard pattern via PATH lookup

What changed

In try_execute_script_via_path_search(), the code already resolves the full path (candidate = PathBuf::from(dir).join(name)) but was discarding it when calling execute_script_content(name, ...). Now passes &candidate.to_string_lossy() instead.

Test plan

  • bash_source_set_via_path_lookup — verifies BASH_SOURCE[0] equals /scripts/test.sh when run by name via PATH
  • bash_source_guard_via_path_lookup — verifies source-guard pattern (BASH_SOURCE[0] == $0) works correctly via PATH
  • All existing bash_source tests still pass (6/6)
  • Full test suite green (2700+ tests)
  • cargo fmt --check clean
  • cargo clippy -- -D warnings clean

Closes #1085

Pass the fully resolved candidate path instead of the bare command name
to execute_script_content() when executing scripts found via PATH lookup.

Closes #1085
@chaliy chaliy merged commit a927695 into main Apr 6, 2026
27 checks passed
@chaliy chaliy deleted the fix/issue-1085-bash-source-path-lookup branch April 6, 2026 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BASH_SOURCE[0] is empty when script is executed via PATH lookup

1 participant