-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.c
42 lines (31 loc) · 765 Bytes
/
env.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
#include "shell.h"
/**
* main - Entry point for a shell that can display environment variables.
*
* Return: Exit status.
*/
extern char **environ;
int environment_builtin_command() {
char *buffer = NULL;
size_t bufsize = 0;
char **args;
char **env;
while (1) {
printf("$ ");
getline(&buffer, &bufsize, stdin);
args = parse_input(buffer);
if (strcmp(args[0], "exit") == 0) {
free(args);
break;
} else if (strcmp(args[0], "env") == 0) {
for (env = environ; *env != NULL; env++) {
printf("%s\n", *env);
}
} else {
execute_command(args);
}
free(args);
}
free(buffer);
return 0;
}