-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4execute.c
40 lines (38 loc) · 1.01 KB
/
4execute.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
#include "shell.h"
/**
* execute_cmd - Execute a command prompt by the user in the shell
* @commands: array of commands, prompt by the user
* @line: line pointer (memory address)
* @env: environment varibale by default
* Return: true on succes or failure if it bool fails
*/
bool execute_cmd(char **commands, char *line, char **env)
{
bool command = false;
if (commands == NULL)
{
free(line);
exit(EXIT_SUCCESS);
}
/* =======E X I T F U N C T I O N ======*/
else if ((_strcmp("exit", commands[0])) == 0)
exit_shell(line, commands);
/*===== E N V F U N C T I O N ========*/
else if ((_strcmp("env", commands[0])) == 0)
{
print_environment();
free(commands);
command = true;
}
/* ======== TRY THE ROUTE WITH THE FORMAT $/bin/ls ============ */
else if (access(commands[0], X_OK) == 0)
execve(commands[0], commands, NULL);
else
{
/*==== TRY THE ROUTE WITH THE FORMAT: $ls===== */
command = exec_routes(commands, line, env);
if (command == false)
return (false);
}
return (command);
}