Skip to content

Commit feb9dee

Browse files
aero_shell: run cmd in bg if ends with &
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent e98c22d commit feb9dee

File tree

1 file changed

+12
-3
lines changed
  • userland/apps/aero_shell/src

1 file changed

+12
-3
lines changed

userland/apps/aero_shell/src/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,19 @@ fn repl(history: &mut Vec<String>) -> Result<(), AeroSyscallError> {
192192
}
193193

194194
_ => {
195+
let mut args = args.collect::<Vec<_>>();
196+
197+
// If the command ends with an `&`, then we have to run the command in the background.
198+
let run_background = args.last().map(|&e| e == "&").unwrap_or(false);
199+
200+
// Remove the `&` from the arguments array if present.
201+
if run_background {
202+
args.pop();
203+
}
204+
195205
let child = sys_fork()?;
196206

197207
if child == 0 {
198-
let args = args.collect::<Vec<_>>();
199208
let mut argv = Vec::new();
200209

201210
argv.push(cmd);
@@ -221,8 +230,8 @@ fn repl(history: &mut Vec<String>) -> Result<(), AeroSyscallError> {
221230
}
222231

223232
sys_exit(0);
224-
} else {
225-
// Wait for the child
233+
} else if !run_background {
234+
// We are not running the command in the background, so wait for the child.
226235
let mut status = 0;
227236
sys_waitpid(child, &mut status, 0)?;
228237

0 commit comments

Comments
 (0)