hysh/main.c
2025-09-26 19:15:23 +02:00

28 lines
668 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
int main(void) {
char buf[256];
char *args[64];
while (1) {
printf("%s ", getuid() ? "$" : "#");
fflush(stdout);
if (!fgets(buf, sizeof(buf), stdin)) break;
buf[strcspn(buf, "\n")] = 0;
if (!buf[0]) continue;
if (!strcmp(buf, "exit")) break;
int i = 0;
char *tok = strtok(buf, " ");
while (tok && i < 63) args[i++] = tok, tok = strtok(NULL, " ");
args[i] = NULL;
if (fork() == 0) execvp(args[0], args), perror("exec"), exit(1);
else wait(NULL);
}
}