Skip to content

env: only suggest -S when an argument contains a space - #16712

Open
shivangithaker-0510 wants to merge 2 commits into
uutils:mainfrom
shivangithaker-0510:fix/16423-env-shebang-hint
Open

shivangithaker-0510 wants to merge 2 commits into
uutils:mainfrom
shivangithaker-0510:fix/16423-env-shebang-hint

Conversation

@shivangithaker-0510

Copy link
Copy Markdown

The 'use -[v]S to pass options in shebang lines' hint was printed for every missing program and after every option error. Print it only when the missing program or the rejected option contains a space, which is when a whole shebang line was passed as one argument, like GNU env.

Closes #16423

The 'use -[v]S to pass options in shebang lines' hint was printed for every missing program and after every option error. Print it only when the missing program or the rejected option contains a space, which is when a whole shebang line was passed as one argument, like GNU env.

Closes uutils#16423
Comment thread src/uu/env/src/env.rs Outdated
let show_shebang_hint = matches!(
e.get(clap::error::ContextKind::InvalidArg),
Some(clap::error::ContextValue::String(arg))
if looks_like_shebang_line(arg.as_bytes())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only works for -v -S cat -n because clap reports - as the invalid arg, no?
checking the raw argument would be more robust

Comment thread tests/by-util/test_env.rs
.stderr_does_not_contain(hint);
new_ucmd!()
.args(&["-v", "-x y"])
.fails_with_code(125)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure GNU doesn't print the hint for -x y? could you please check it?

Comment thread src/uu/env/src/env.rs Outdated
/// line such as `cat -n` was passed as a single argument. Only then is the
/// hint to use `-S` worth printing.
fn looks_like_shebang_line(arg: &[u8]) -> bool {
arg.contains(&b' ')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about tabs? the issue says whitespace

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/env/env-S. tests/env/env-S is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/tail/follow-name is no longer failing!
Congrats! The gnu test tests/tail/pid-pipe is no longer failing!

…whitespace option

Match GNU env: the hint is shown when a missing program name contains
whitespace (space, tab, newline, vertical tab, form feed or carriage
return), or when the rejected short option is itself a whitespace
character, as for '-v -S cat -n'. An unknown option that merely contains
whitespace ('-x y', '--foo bar') does not get the hint.
@codspeed

codspeed Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will regress 1 benchmark

3 warnings

⚠️ 54 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 4 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 4 benchmarks with a significant change ran in a different software environment

Their base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the changes might come from this difference rather than from the code. Open an affected benchmark to see what changed.

See affected benchmarks

⚡ 3 improved benchmarks
❌ 1 regressed benchmark
✅ 97 untouched benchmarks
⏩ 382 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ du_wide_tree[(5000, 500)] 15.6 ms 16.3 ms -4.18%
⚡ false_consecutive_calls 350.2 ns 294.7 ns +18.85%
⚡ cksum_crc 34.2 ms 33.1 ms +3.36%
⚡ cksum_multiple_files 51.1 ms 49.5 ms +3.27%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing shivangithaker-0510:fix/16423-env-shebang-hint (4df81ae) with main (9311390)2

Open in CodSpeed

Footnotes

  1. 382 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (276ffe9) during the generation of this report, so 9311390 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

env: shebang hint printed for every missing program and option error

2 participants