From 8d8e1e5928278395779e4d7fd45eb67770c81c6d Mon Sep 17 00:00:00 2001 From: Jay Hemnani <193022578+jayhemnani9910@users.noreply.github.com> Date: Mon, 26 Oct 2026 15:27:51 +0530 Subject: [PATCH 1/2] ps: leave out the header line when every header is empty ps -o pid= still printed a header row made of spaces, so the first line of output was blank. procps-ng, as its man page says, prints no header line when all column headers are empty. --- src/uu/ps/src/ps.rs | 5 ++++- tests/by-util/test_ps.rs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/uu/ps/src/ps.rs b/src/uu/ps/src/ps.rs index 5ee1af3c..8ee51cab 100644 --- a/src/uu/ps/src/ps.rs +++ b/src/uu/ps/src/ps.rs @@ -113,7 +113,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let mut table = Table::new(); table.set_format(*FORMAT_CLEAN); - if !matches.get_flag("no-headers") { + // As in procps-ng, the header line is left out when every header is + // empty, e.g. `ps -o pid= -o comm=`. + let all_headers_empty = code_mapping.iter().all(|(_, header)| header.is_empty()); + if !matches.get_flag("no-headers") && !all_headers_empty { let header = code_mapping .iter() .map(|(_, header)| header) diff --git a/tests/by-util/test_ps.rs b/tests/by-util/test_ps.rs index d6bb2531..c7515842 100644 --- a/tests/by-util/test_ps.rs +++ b/tests/by-util/test_ps.rs @@ -204,6 +204,25 @@ fn test_no_headers_flags() { } } +#[test] +#[cfg(target_os = "linux")] +fn test_all_empty_headers_print_no_header_line() { + new_ucmd!() + .args(&["-o", "pid=", "-p", "1"]) + .succeeds() + .stdout_matches(&Regex::new(r"\A *1 *\n\z").unwrap()); + new_ucmd!() + .args(&["-o", "pid=", "-o", "ppid=", "-p", "1"]) + .succeeds() + .stdout_matches(&Regex::new(r"\A *1 +0 *\n\z").unwrap()); + + // One named header keeps the header line. + new_ucmd!() + .args(&["-o", "pid=,ppid", "-p", "1"]) + .succeeds() + .stdout_matches(&Regex::new(r"\A +PPID *\n *1 +0 *\n\z").unwrap()); +} + #[test] #[cfg(target_os = "linux")] fn test_deselect() { From cf681814938616cfddcaa46075c20f8846555262 Mon Sep 17 00:00:00 2001 From: Jay Hemnani <193022578+jayhemnani9910@users.noreply.github.com> Date: Sun, 15 Nov 2026 10:26:08 +0530 Subject: [PATCH 2/2] ps: use separate -o options in the named header test --- tests/by-util/test_ps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/by-util/test_ps.rs b/tests/by-util/test_ps.rs index c7515842..9af72dbd 100644 --- a/tests/by-util/test_ps.rs +++ b/tests/by-util/test_ps.rs @@ -218,7 +218,7 @@ fn test_all_empty_headers_print_no_header_line() { // One named header keeps the header line. new_ucmd!() - .args(&["-o", "pid=,ppid", "-p", "1"]) + .args(&["-o", "pid=", "-o", "ppid", "-p", "1"]) .succeeds() .stdout_matches(&Regex::new(r"\A +PPID *\n *1 +0 *\n\z").unwrap()); }