Luna/shell/builtin/unset.cpp
apio 7a4d3ba495
All checks were successful
continuous-integration/drone/push Build is passing
sh: Add a few more shell builtins
2023-07-21 21:06:10 +02:00

20 lines
578 B
C++

#include "sh.h"
#include <errno.h>
#include <os/ArgumentParser.h>
#include <stdlib.h>
shell_builtin_t builtin_unset = [](int argc, char** argv) -> Result<void> {
StringView name;
os::ArgumentParser parser;
parser.set_should_exit_on_bad_usage(false);
parser.add_description("Remove an environment variable (shell builtin)"_sv);
parser.add_system_program_info("unset"_sv);
parser.add_positional_argument(name, "name"_sv, true);
if (!TRY(parser.parse(argc, argv))) return {};
if (unsetenv(name.chars()) < 0) return err(errno);
return {};
};