Skip to content

feat(interpreter): implement BASH_SOURCE array variable#832

Merged
chaliy merged 1 commit intomainfrom
fix/issue-825-bash-source
Mar 26, 2026
Merged

feat(interpreter): implement BASH_SOURCE array variable#832
chaliy merged 1 commit intomainfrom
fix/issue-825-bash-source

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Mar 26, 2026

Summary

  • Implement BASH_SOURCE array variable tracking source file names across the call stack
  • Add bash_source_stack: Vec<String> field to Interpreter
  • Push/pop in execute_script_content, execute_source, and execute_function_call
  • Supports the source guard pattern: [[ "${BASH_SOURCE[0]}" == "$0" ]]

Test plan

  • bash_source_set_in_script — BASH_SOURCE[0] set when executing script by path
  • bash_source_set_in_sourced_file — BASH_SOURCE[0] set when sourcing
  • bash_source_guard_direct_execution — guard detects direct execution
  • bash_source_guard_sourced — guard detects sourced context
  • Full test suite passes

Closes #825

Closes #825 — add BASH_SOURCE tracking via bash_source_stack field on
Interpreter. Updated in execute_script_content, execute_source, and
execute_function_call to maintain source file stack.

BASH_SOURCE[0] reflects the current source file, with depth increasing
for nested source/function calls. Supports the common source guard
pattern: `[[ "${BASH_SOURCE[0]}" == "$0" ]] && main "$@"`
@chaliy chaliy merged commit 978d076 into main Mar 26, 2026
18 of 23 checks passed
@chaliy chaliy deleted the fix/issue-825-bash-source branch March 26, 2026 14:44
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.

feat(interpreter): implement BASH_SOURCE array variable

1 participant