forked from EugeneJoe/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuilt_in_shell.c
43 lines (42 loc) · 863 Bytes
/
built_in_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
#include "shellheader.h"
/**
* built_in - works out which built-in functions to be called when necessary
* @args: arguments passed on command line
* @env: double pointer to our environment
*
* Return: 0 on success, -1 if failed
*/
int built_in(char **args, char **env)
{
if (_strcmp(args[0], "env") == 0)
{
return (printenv(env));
}
else if (_strcmp(args[0], "setenv") == 0)
{
return (_setenv(args[1], args[2], env));
}
else if (_strcmp(args[0], "unsetenv") == 0)
{
return (_unsetenv(args[1], env));
}
else if (_strcmp(args[0], "cd") == 0)
{
return (_cd(args, env));
}
else if (_strcmp(args[0], "help") == 0)
{
display_help(args, 0);
return (0);
}
else if (_strcmp(args[0], "history") == 0)
{
return (disp_hist(args, 0));
}
else if (_strcmp(args[0], "^C") == 0)
{
handle_sigint(SIGINT);
return (0);
}
return (-1);
}