mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +00:00
Shell: Add support for unset -v
in POSIX mode
This commit is contained in:
parent
71441ea932
commit
e2336d9de5
1 changed files with 4 additions and 1 deletions
|
@ -1198,9 +1198,12 @@ ErrorOr<int> Shell::builtin_wait(Main::Arguments arguments)
|
||||||
ErrorOr<int> Shell::builtin_unset(Main::Arguments arguments)
|
ErrorOr<int> Shell::builtin_unset(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
Vector<DeprecatedString> vars;
|
Vector<DeprecatedString> vars;
|
||||||
|
bool unset_only_variables = false; // POSIX only.
|
||||||
|
|
||||||
Core::ArgsParser parser;
|
Core::ArgsParser parser;
|
||||||
parser.add_positional_argument(vars, "List of variables", "variables", Core::ArgsParser::Required::Yes);
|
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))
|
if (!parser.parse(arguments, Core::ArgsParser::FailureBehavior::PrintUsage))
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1212,7 +1215,7 @@ ErrorOr<int> Shell::builtin_unset(Main::Arguments arguments)
|
||||||
|
|
||||||
if (TRY(lookup_local_variable(value)) != nullptr) {
|
if (TRY(lookup_local_variable(value)) != nullptr) {
|
||||||
unset_local_variable(value);
|
unset_local_variable(value);
|
||||||
} else {
|
} else if (!unset_only_variables) {
|
||||||
unsetenv(value.characters());
|
unsetenv(value.characters());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue