uutils / uutils/coreutils

POSIXLY_CORRECT is ignored for option parsing: options after operands are still parsed

Open
#14,621 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

Summary

GNU getopt stops option processing at the first non-option argument when POSIXLY_CORRECT is set in the environment, everything after the first operand is treated as an operand. This is documented in the coreutils manual "Common options": "if the POSIXLY_CORRECT environment variable is set, options must appear before operands" and in getopt(3).

uutils utilities (clap-based parsing) ignore POSIXLY_CORRECT here and keep permuting options and operands. This affects all clap-parsed utilities, not just rm. rm is just the case where the difference is most consequential.

Details

POSIXLY_CORRECT is currently only consulted for utility-specific semantics (block sizes in df/du, echo escapes, wc, pwd, ls, ...), not for argument ordering.

Not affected: basename, seq, tr (stop after operands anyway); echo, expr, test, true, false (no getopt options); env, nice, nohup, stdbuf (always stop at the first operand); stty (own parser). join and pr are excluded because GNU itself does not honor POSIXLY_CORRECT there.

PoC

Reproduced on the 0.11.0 release and on current main (c7b4ee8, 2026-09-01)

$ mkdir -p test/dir/sub; touch test/dir/a test/dir/sub/b
$ POSIXLY_CORRECT=1 rm test -rf    # (GNU coreutils) 9.7
rm: cannot remove 'test': Is a directory
rm: cannot remove '-rf': No such file or directory
$ echo $?
1
$ ls -d test
test
$ POSIXLY_CORRECT=1 coreutils rm test -rf
$ echo $?; ls -d test
0
ls: cannot access 'test': No such file or directory
$ POSIXLY_CORRECT=1 ls . -l
GNU: ls: cannot access '-l': No such file or directory, followed by compact listing of .
uutils: long listing of '.'
$ echo "data" > x ; POSIXLY_CORRECT=1 cat x -n
GNU: cat: -n: No such file or directory
uutils: prints x with line numbers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the shared clap-based argument parsing used by the affected utilities, then compare the POSIXLY_CORRECT behavior in the rm, ls, and cat examples with the GNU results. Verify which listed utilities are excluded and test that options after the first operand remain operands when the environment variable is set, while normal parsing is unchanged otherwise.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.