Skip to content

more: print Pattern not found when output is piped - #16993

Open
aaron-ang wants to merge 8 commits into
uutils:mainfrom
aaron-ang:more-pipe-pattern-not-found
Open

aaron-ang wants to merge 8 commits into
uutils:mainfrom
aaron-ang:more-pipe-pattern-not-found

Conversation

@aaron-ang

@aaron-ang aaron-ang commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

With -P and no matching line, more piped to a file or pipe wrote the file silently, while util-linux prints Pattern not found first. Also, every file was searched for the pattern instead of only the first input.

Now Pattern not found is printed before the file, byte for byte as util-linux does: no newline, and three spaces before a header. The start line and pattern apply only to the first input, even one that can't be opened, and piped stdin uses them up as the first input.

Depends on #16944.

Part of #16940

Piped stdin comes first, and a header with the file name comes before
each file when there is more than one input. -F and -P still pick the
first line written.
Read errors are still reported per input, including piped stdin, and the next input is shown. Add a CannotRead error and share the header rule with the pager.
musl says "I/O error" where glibc says "Input/output error", so build
the expected message from the platform's strerror.
Searching for the pattern kept every line read, so a file without a
match ended up in memory. Hold one line at a time and seek back to
where the search started; a FIFO can't seek, so nothing is shown.

Report stdin read errors with MoreError::CannotRead like files.
When stdout isn't a terminal, write every input unchanged, the way less
does, so the output can be used as data. The start line and pattern
still apply when paging.
…ttern"

This reverts commit 1f1553d. util-linux applies the start line and
pattern to piped output too, and compatibility with it comes first.
When output isn't a terminal, print "Pattern not found" on its own line
before the file, like the pager does. The start line and pattern now
only apply to the first input, even one that can't be opened.
Copilot AI balanced review requested due to automatic review settings November 29, 2026 19:53

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Piped output is part of the contract, so match util-linux byte for byte:
no newline after the message, and three spaces before a header.
Copilot AI balanced review requested due to automatic review settings November 29, 2026 20:07

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

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.

2 participants