diff --git a/Userland/Utilities/su.cpp b/Userland/Utilities/su.cpp index d101f45f76..6a4a97deea 100644 --- a/Userland/Utilities/su.cpp +++ b/Userland/Utilities/su.cpp @@ -21,11 +21,13 @@ ErrorOr serenity_main(Main::Arguments arguments) StringView first_positional; StringView second_positional; + DeprecatedString command; bool simulate_login = false; Core::ArgsParser args_parser; args_parser.add_positional_argument(first_positional, "See --login", "-", Core::ArgsParser::Required::No); args_parser.add_positional_argument(second_positional, "User to switch to (defaults to user with UID 0)", "user", Core::ArgsParser::Required::No); + args_parser.add_option(command, "Command to execute", "command", 'c', "command"); args_parser.add_option(simulate_login, "Simulate login", "login", 'l'); args_parser.parse(arguments); @@ -60,6 +62,11 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Core::System::setenv("HOME"sv, account.home_directory(), true)); - TRY(Core::System::exec(account.shell(), Array { account.shell().view() }, Core::System::SearchInPath::No)); + if (command.is_null()) { + TRY(Core::System::exec(account.shell(), Array { account.shell().view() }, Core::System::SearchInPath::No)); + } else { + TRY(Core::System::exec(account.shell(), Array { account.shell().view(), "-c"sv, command.view() }, Core::System::SearchInPath::No)); + } + return 1; }