-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.c
More file actions
50 lines (42 loc) · 813 Bytes
/
shell.c
File metadata and controls
50 lines (42 loc) · 813 Bytes
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
#include "main.h"
/**
* main- entry point
* Return: 0 when exit
*/
int main(void)
{
char *buffer = NULL, **args;
size_t n = 0, len;
int status;
while (1)
{
_is_interactive();
len = getline(&buffer, &n, stdin);
_eof_handle(buffer, len);
if (len > 0 && buffer[len - 1] == '\n')
buffer[len - 1] = '\0';
args = _split(buffer, " \t");
if (args && args[0])
{
if (_strcmp(args[0], "exit") == 1)
{
if (args[1] != NULL)
status = _atoi(args[1]);
else
status = _status();
free(buffer);
_free_args(args);
exit(status);
}
else if (_strcmp(args[0], "env") == 1)
_env();
else if (access(args[0], F_OK) == 0 && access(args[0], X_OK) == 0)
_exec(args);
else
_path_then_exec(args);
}
_free_args(args);
}
free(buffer);
return (0);
}