Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Aug 20, 2024
1 parent 14b7d88 commit dea06b1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,22 @@ fn read_rc_file(core: &mut ShellCore) {
}

fn main() {
let mut arg_offset = 0;

let args: Vec<String> = env::args().collect();
if args.len() > 1 && args[1] == "--version" {
show_version();
}

let mut options = args.clone();
let mut parameters = args.clone();

let script = if args.len() > 1 && ! args[1].starts_with("-") {
options.remove(1);
parameters.remove(0);
args[1].clone()
}else if args.len() > 2 && args[1].starts_with("-") {
}else if args.len() > 2 && args[1].starts_with("-") { //for shebang with option
options.remove(2);
parameters.remove(0);
parameters.remove(0);
args[2].clone()
}else{
"-".to_string()
Expand All @@ -90,7 +96,6 @@ fn main() {
if script != "-" {
match File::open(&script) {
Ok(file) => {
arg_offset += 1;
let fd = file.into_raw_fd();
let result = io::replace(fd, 0);
if ! result {
Expand All @@ -106,7 +111,8 @@ fn main() {

let mut core = ShellCore::new();
core.script_name = script;
builtins::option_commands::set(&mut core, &mut args[arg_offset..].to_vec());
builtins::option_commands::set(&mut core, &mut options);
builtins::option_commands::set_parameters(&mut core, &mut parameters);
run_signal_check(&mut core);
read_rc_file(&mut core);
main_loop(&mut core);
Expand Down
4 changes: 4 additions & 0 deletions test/lineno.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -xv

echo $0
echo $1
2 changes: 1 addition & 1 deletion test/lineno.sush
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sush
#!/bin/sush -xv

echo $0
echo $1

0 comments on commit dea06b1

Please sign in to comment.