-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuiltins_handler.c
More file actions
35 lines (34 loc) · 875 Bytes
/
Copy pathbuiltins_handler.c
File metadata and controls
35 lines (34 loc) · 875 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
#include "shell.h"
/**
* execute_builtin - Execute built-in shell commands
* @lsh: Shell structure containing command tokens
*
* Return: Exit status if 'exit' command is executed, otherwise 18.
*/
int execute_builtin(shell_t *lsh)
{
if (!_strcmp(lsh->tokenized_commands[0], "exit"))
{
return (exit_shell(lsh, free_up));
}
else if (!_strcmp(lsh->tokenized_commands[0], "setenv"))
{
if (lsh->tokenized_commands[1] && lsh->tokenized_commands[2])
return (_setenv(lsh->tokenized_commands[1], lsh->tokenized_commands[2], 1));
return (1);
}
else if (!_strcmp(lsh->tokenized_commands[0], "unsetenv"))
{
if (lsh->tokenized_commands[1])
{
return (_unsetenv(lsh->tokenized_commands[1]));
}
}
else if (!_strcmp(lsh->tokenized_commands[0], "printenv") ||
!_strcmp(lsh->tokenized_commands[0], "env"))
{
_printenv();
return (0);
}
return (18);
}