forked from ikramikram2020/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.c
More file actions
55 lines (52 loc) · 1.09 KB
/
Copy pathshell.c
File metadata and controls
55 lines (52 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
#include "shell.h"
/**
* main - Main function for the custom shell to execute commands and manage
* user interactions with the operating system.
*
* @argc: Number of command-line arguments.
* @argv: Array of strings representing command-line arguments.
* @env: Array of strings representing environment variables.
*
* Return: 0 on success, -1 on failure.
*/
int main(int argc, char **argv, char **env)
{
int count = 1;
(void)argc;
while (1)
{
char *get_input;
char **full_command;
_print_prompt();
get_input = _get_input();
if (get_input[0] == '\n' || get_input == NULL)
{
free(get_input);
continue;
}
full_command = _create_command(get_input);
free(get_input);
get_input = NULL;
if (full_command == NULL)
continue;
if (_check_exit(full_command) == -1)
{
_error_handler(argv[0], count, full_command, 0);
_free_command(full_command);
if (!isatty(STDIN_FILENO))
exit(2);
count++;
continue;
}
if (_strncmp(full_command[0], "env", 3) == 0)
{
_print_env(env);
continue;
}
_execute_command(argv, full_command, count, env);
_free_command(full_command);
full_command = NULL;
count++;
}
return (0);
}