From e2336d9de57e80fab6089fe58686745bf29f930a Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Wed, 19 Apr 2023 12:17:38 +0330 Subject: [PATCH] Shell: Add support for `unset -v` in POSIX mode --- Userland/Shell/Builtin.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Shell/Builtin.cpp b/Userland/Shell/Builtin.cpp index c6ca3fb3bd..9fb6c67d34 100644 --- a/Userland/Shell/Builtin.cpp +++ b/Userland/Shell/Builtin.cpp @@ -1198,9 +1198,12 @@ ErrorOr Shell::builtin_wait(Main::Arguments arguments) ErrorOr Shell::builtin_unset(Main::Arguments arguments) { Vector vars; + bool unset_only_variables = false; // POSIX only. Core::ArgsParser parser; parser.add_positional_argument(vars, "List of variables", "variables", Core::ArgsParser::Required::Yes); + if (m_in_posix_mode) + parser.add_option(unset_only_variables, "Unset only variables", "variables", 'v'); if (!parser.parse(arguments, Core::ArgsParser::FailureBehavior::PrintUsage)) return 1; @@ -1212,7 +1215,7 @@ ErrorOr Shell::builtin_unset(Main::Arguments arguments) if (TRY(lookup_local_variable(value)) != nullptr) { unset_local_variable(value); - } else { + } else if (!unset_only_variables) { unsetenv(value.characters()); } }