-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyShell.c
More file actions
40 lines (35 loc) · 696 Bytes
/
Copy pathmyShell.c
File metadata and controls
40 lines (35 loc) · 696 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
#include "shell.h"
#include <stdio.h>
#include <unistd.h>
/**
* main - Entry point of simple shell
* @argc: arg count
* @argv: arg vector
*
* Return: 0 on success, 1 on error
*/
int main(int argc, char **argv)
{
char *userInput = NULL;
char **command = NULL;
int status = 0, index = 0;
(void) argc;
while (true)
{
userInput = getInput();
if (userInput == NULL) /* C-d */
{
if (isatty(STDIN_FILENO))
write(STDOUT_FILENO, "\n", 1);
return (status);
}
index++;
command = tokenizer(userInput);
if (!command)
continue;
if (is_builtin(command[0]))
handleBuiltin(command, argv, &status, index);
else
status = execCommand(command, argv, index);
}
}