Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/bashkit/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2686,8 +2686,20 @@ impl Interpreter {
self.pipeline_stdin = stdin.clone();
}

// Set BASH_SOURCE for script file execution
if let Some(ref file) = script_file {
self.bash_source_stack.push(file.clone());
self.update_bash_source();
}

let result = self.execute(&script).await;

// Restore BASH_SOURCE
if script_file.is_some() {
self.bash_source_stack.pop();
self.update_bash_source();
}

// Restore stdin
self.pipeline_stdin = saved_stdin;

Expand Down
15 changes: 15 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/bash-source-var.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### bash_source_in_executed_script
# BASH_SOURCE[0] should equal script path when run via bash
echo 'echo "${BASH_SOURCE[0]}"' > /tmp/bsrc_test.sh
bash /tmp/bsrc_test.sh
### expect
/tmp/bsrc_test.sh
### end

### bash_source_dirname_pattern
# Common pattern: find script's own directory
echo 'echo "$(dirname "${BASH_SOURCE[0]}")"' > /tmp/bsrc_dir.sh
bash /tmp/bsrc_dir.sh
### expect
/tmp
### end
Loading