rumpk/apps/test_shell.c

34 lines
777 B
C

// Minimal test shell to verify the execution environment
#include <stddef.h>
extern int write(int fd, const void *buf, size_t count);
extern int read(int fd, void *buf, size_t count);
int main(int argc, char *argv[], char *envp[]) {
const char *prompt = "shell> ";
char buf[128];
while (1) {
// Print prompt
write(1, prompt, 7);
// Read command
int n = read(0, buf, sizeof(buf) - 1);
if (n <= 0) continue;
buf[n] = '\0';
// Echo back
write(1, "You typed: ", 11);
write(1, buf, n);
// Check for exit
if (buf[0] == 'q' && buf[1] == '\n') {
write(1, "Goodbye!\n", 9);
break;
}
}
return 0;
}