From a9da3d1fc8e13857778ea9987ba8a54c6091bf56 Mon Sep 17 00:00:00 2001 From: emirmrkaljevic <93012621+emirmrkaljevic@users.noreply.github.com> Date: Tue, 10 Nov 2026 21:53:56 +0100 Subject: [PATCH] sysctl: treat -o and -x as flags that take no value procps-ng documents -o and -x as no-ops for BSD compatibility. They must not consume the next operand, so sysctl -o kernel.ostype prints the key instead of treating the key as an argument to -o. --- src/uu/sysctl/src/sysctl.rs | 2 ++ tests/by-util/test_sysctl.rs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/uu/sysctl/src/sysctl.rs b/src/uu/sysctl/src/sysctl.rs index 7a3d9e96..eef80099 100644 --- a/src/uu/sysctl/src/sysctl.rs +++ b/src/uu/sysctl/src/sysctl.rs @@ -234,11 +234,13 @@ pub fn uu_app() -> Command { .arg( Arg::new("noop_o") .short('o') + .action(ArgAction::SetTrue) .help("Does nothing, for BSD compatibility"), ) .arg( Arg::new("noop_x") .short('x') + .action(ArgAction::SetTrue) .help("Does nothing, for BSD compatibility"), ) } diff --git a/tests/by-util/test_sysctl.rs b/tests/by-util/test_sysctl.rs index 100a13e2..23c7fcc5 100644 --- a/tests/by-util/test_sysctl.rs +++ b/tests/by-util/test_sysctl.rs @@ -118,6 +118,28 @@ mod linux { .code_is(1) .no_stdout(); } + + // procps-ng treats -o and -x as no-op flags (BSD compatibility), not options + // that take a value. Without SetTrue, clap would consume the next operand. + #[test] + fn test_noop_flags_do_not_take_a_value() { + new_ucmd!() + .args(&["-o", "kernel.ostype"]) + .succeeds() + .stdout_is("kernel.ostype = Linux\n"); + new_ucmd!() + .args(&["-x", "kernel.ostype"]) + .succeeds() + .stdout_is("kernel.ostype = Linux\n"); + new_ucmd!() + .args(&["-o", "-n", "kernel.ostype"]) + .succeeds() + .stdout_is("Linux\n"); + new_ucmd!() + .args(&["-ox", "kernel.ostype"]) + .succeeds() + .stdout_is("kernel.ostype = Linux\n"); + } } #[cfg(not(target_os = "linux"))]