File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -2686,8 +2686,20 @@ impl Interpreter {
26862686 self . pipeline_stdin = stdin. clone ( ) ;
26872687 }
26882688
2689+ // Set BASH_SOURCE for script file execution
2690+ if let Some ( ref file) = script_file {
2691+ self . bash_source_stack . push ( file. clone ( ) ) ;
2692+ self . update_bash_source ( ) ;
2693+ }
2694+
26892695 let result = self . execute ( & script) . await ;
26902696
2697+ // Restore BASH_SOURCE
2698+ if script_file. is_some ( ) {
2699+ self . bash_source_stack . pop ( ) ;
2700+ self . update_bash_source ( ) ;
2701+ }
2702+
26912703 // Restore stdin
26922704 self . pipeline_stdin = saved_stdin;
26932705
Original file line number Diff line number Diff line change 1+ # ## bash_source_in_executed_script
2+ # BASH_SOURCE[0] should equal script path when run via bash
3+ echo ' echo "${BASH_SOURCE[0]}"' > /tmp/bsrc_test.sh
4+ bash /tmp/bsrc_test.sh
5+ # ## expect
6+ /tmp/bsrc_test.sh
7+ # ## end
8+
9+ # ## bash_source_dirname_pattern
10+ # Common pattern: find script's own directory
11+ echo ' echo "$(dirname "${BASH_SOURCE[0]}")"' > /tmp/bsrc_dir.sh
12+ bash /tmp/bsrc_dir.sh
13+ # ## expect
14+ /tmp
15+ # ## end
You can’t perform that action at this time.
0 commit comments