// I am the shell you are currently executing
use std::io::{self, BufRead, Write};
use std::process::{Command, Stdio};
use std::env;
use std::str;
fn valid(s: &[u8]) -> bool {
s.iter().all(|&c| (b'a' <= c && c <= b'z') || c == b' ' || c == b'>')
}
fn prompt() {
print!("$ ");
io::stdout().flush().unwrap();
}
fn run(cmd: &str) -> Vec<u8> {
Command::new("/bin/bash")
.arg("-c")
.arg(cmd)
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::null())
.output()
.unwrap()
.stdout
}
fn main() {
env::set_current_dir("/dev/shm").unwrap();
let stdin = io::stdin();
let mut stdout = io::stdout();
prompt();
for l in stdin.lock().split(b'\n') {
let l = l.unwrap();
if valid(&l) {
let l = String::from_utf8(l).unwrap();
let data = run(&l);
stdout.write(&data).unwrap();
} else {
println!("Bad character");
}
prompt();
}
}