summaryrefslogtreecommitdiff
path: root/42sh/src/builtins/unset.c
diff options
context:
space:
mode:
Diffstat (limited to '42sh/src/builtins/unset.c')
-rw-r--r--42sh/src/builtins/unset.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/42sh/src/builtins/unset.c b/42sh/src/builtins/unset.c
new file mode 100644
index 0000000..77b323a
--- /dev/null
+++ b/42sh/src/builtins/unset.c
@@ -0,0 +1,44 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "builtins.h"
+#include "utils/env.h"
+
+int unset(struct string **args)
+{
+ size_t i = 0;
+ int var = 0;
+ int fun = 0;
+ while (args[i] != NULL && args[i]->data[0] == '-')
+ {
+ if (args[i]->data[1] == 'v')
+ {
+ var = 1;
+ i += 1;
+ }
+ else if (args[i]->data[1] == 'f')
+ {
+ fun = 1;
+ i += 1;
+ }
+ else
+ {
+ break;
+ }
+ }
+ if (var == 0 && fun == 0)
+ {
+ var = 1;
+ fun = 1;
+ }
+ // TODO unset with flag -f
+ while (args[i] != NULL)
+ {
+ env_unset(args[i]->data);
+ i += 1;
+ }
+ fflush(stdout);
+ return 0;
+}