forked from UdayPrakash-dev/Shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminishell.c
More file actions
57 lines (46 loc) · 1.09 KB
/
Copy pathminishell.c
File metadata and controls
57 lines (46 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include "shell.h"
#define MAX_INPUT 1024
#define MAX_ARGS 64
// // Function prototypes
// void read_command(char *input);
// void parse_command(char *input, char **args);
// void execute_command(char **args);
// void change_directory(char **args);
int main()
{
char input[MAX_INPUT];
char *args[MAX_ARGS];
while (1)
{
// Print prompt
printf("Enigma> ");
fflush(stdout);
// Read input
read_command(input);
// Parse input
parse_command(input, args);
// Empty input → skip
if (args[0] == NULL)
continue;
// Built-in: exit
if (strcmp(args[0], "exit") == 0)
{
printf("Exiting shell... bye!\n");
break;
}
// Built-in: cd
if (strcmp(args[0], "cd") == 0)
{
change_directory(args);
continue;
}
// Otherwise, execute external command
execute_command(args);
}
return 0;
}