add environ builtin
This commit is contained in:
parent
cf4161d545
commit
f580c03ebc
@ -30,6 +30,10 @@ bool is_builtin(char *command) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp(command, "environ") == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -40,6 +44,9 @@ void run_builtin(StringArray *args) {
|
||||
else if (strcmp(args->array[0], "cd") == 0) {
|
||||
change_directory(args);
|
||||
}
|
||||
else if (strcmp(args->array[0], "environ") == 0) {
|
||||
print_environ(args);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Builtin %s does not exist!\n", args->array[0]);
|
||||
}
|
||||
@ -72,3 +79,13 @@ void change_directory(StringArray *args) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_environ(StringArray *args) {
|
||||
if (args->size > 1) {
|
||||
fprintf(stderr, "Too many arguments!\n");
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < variables->size; i++) {
|
||||
fprintf(stdout, "%s=%s\n", variables->keys->array[i], variables->values->array[i]);
|
||||
}
|
||||
}
|
||||
|
@ -44,4 +44,10 @@ void exit_shell(StringArray *args);
|
||||
*/
|
||||
void change_directory(StringArray *args);
|
||||
|
||||
/**
|
||||
* Print all of the environment variables.
|
||||
* @param args The arguments the user input.
|
||||
*/
|
||||
void print_environ(StringArray * args);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user