-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsimple_shell.c
49 lines (48 loc) · 1013 Bytes
/
simple_shell.c
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
#include "shell.h"
/**
* main - main arguments functions
* @ac:count of argumnents
* @av: arguments
* @env: environment
* Return: _exit = 0.
*/
int main(int ac, char **av, char **env)
{
char *getcommand = NULL, **user_command = NULL;
int pathValue = 0, _exit = 0, n = 0;
(void)ac;
while (1)
{
getcommand = _getline_command();
if (getcommand)
{
pathValue++;
user_command = _get_token(getcommand);
if (!user_command)
{
free(getcommand);
continue;
}
if ((!_strcmp(user_command[0], "exit")) && user_command[1] == NULL)
_exit_command(user_command, getcommand, _exit);
if (!_strcmp(user_command[0], "env"))
_getenv(env);
else
{
n = _values_path(&user_command[0], env);
_exit = _fork_fun(user_command, av, env, getcommand, pathValue, n);
if (n == 0)
free(user_command[0]);
}
free(user_command);
}
else
{
if (isatty(STDIN_FILENO))
write(STDOUT_FILENO, "\n", 1);
exit(_exit);
}
free(getcommand);
}
return (_exit);
}