Add status variable

This commit is contained in:
g1n 2021-07-20 09:47:02 +00:00
parent 43e82b822b
commit 746790f91b
1 changed files with 13 additions and 2 deletions

View File

@ -4,6 +4,9 @@ use std::process::Command;
use std::path::Path;
fn main() {
// Variables
let mut STATUS = 0;
loop {
print!("$ ");
io::stdout().flush();
@ -16,8 +19,16 @@ fn main() {
let args = parts;
match command {
"true" | ":" => {
STATUS = 0;
},
"echo" => {
println!("{}", args.peekable().peek().map_or("/", |x| *x));
let args = args.peekable().peek().map_or("/", |x| *x);
if args.clone() == "$STATUS" {
println!("{}", STATUS);
} else {
println!("{}", args);
}
},
"cd" => {
let new_dir = args.peekable().peek().map_or("/", |x| *x);
@ -34,7 +45,7 @@ fn main() {
match child {
Ok(mut child) => { child.wait(); },
Err(e) => eprintln!("{}", e),
Err(e) => { STATUS=1; eprintln!("{}", e); },
};
}
}