forked from Hordunlarmy/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilt_in_function.c
More file actions
61 lines (59 loc) · 1023 Bytes
/
built_in_function.c
File metadata and controls
61 lines (59 loc) · 1023 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "main.h"
/**
* built_ins - Entry point
* @args: command and arguments
* @line_num: execution count
* Return: Always 0 (Success)
*/
int built_ins(char **args, int line_num)
{
if (args[0] == NULL)
return (1);
if (_strcmp(args[0], "exit") == 0)
{
my_exit(args);
exit(2);
}
if (_strcmp(args[0], "env") == 0)
{
my_env();
return (1);
}
if (_strcmp(args[0], "cd") == 0)
{
my_cd(args, line_num);
return (1);
}
if (_strcmp(args[0], "setenv") == 0)
{
my_setenv(args[1], args[2], 1);
return (1);
}
if (_strcmp(args[0], "unsetenv") == 0)
{
my_unsetenv(args);
return (1);
}
return (0);
}
/**
* built_ins2 - Entry point
* @args: command and arguments
* @line_num: execution count
* Return: Always 0 (Success)
*/
int built_ins2(char **args, int line_num __attribute__ ((unused)))
{
if (_strcmp(args[0], "alias") == 0)
{
my_alias(args);
return (1);
}
if (_strcmp(args[0], "echo") == 0)
{
my_echo(args);
write(STDOUT_FILENO, "\n", 1);
return (1);
}
return (0);
}