docs(rules): grep -r on a single file omits the filename on GNU, not BSD - #2334
Open
laurigates wants to merge 1 commit into
Open
docs(rules): grep -r on a single file omits the filename on GNU, not BSD#2334laurigates wants to merge 1 commit into
laurigates wants to merge 1 commit into
Conversation
A guard that greps a file list and parses FILE:LINE:TEXT is correct on macOS and silently mis-parses on Linux whenever the list happens to hold ONE entry: GNU grep drops the filename prefix for a single file argument while BSD keeps it, so the parse shifts a field and reads the line number as the filename. Distilled from a live break rather than a hypothetical: scripts/check-dead-api-endpoints.sh was 17/17 green locally and failed one assertion on its first Linux CI run, reporting FILE=2. A fixture cannot catch this class — the fixture runs on whichever grep the author has — so the rule states plainly that running on both platforms is the only detector and -H is the one-flag fix. Lands in shell-scripting.md's existing GNU-vs-BSD section beside the two BSD date traps, which are the same shape: an implementation-dependent default where the portable form costs one flag. The file is path-scoped to **/*.sh and scripts/**, so this adds nothing to the always-loaded surface; check-context-engineering.py --strict still exits 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
greprow and a subsection toshell-scripting.md's existing GNU vs BSD Tool Differences section.grep -ron a single file argument printsline:texton GNU andfile:line:texton BSD. A guard that greps a file list and parsesFILE:LINE:TEXTtherefore works on macOS and silently mis-parses on Linux whenever the list happens to hold one entry — the parse shifts a field and reads the line number as the filename.Distilled from a live break, not a hypothetical
scripts/check-dead-api-endpoints.sh(#2321) was 17/17 green on macOS and failed one assertion on its first Linux CI run, reportingFILE=2.The part worth writing down is that a fixture cannot catch this class — the fixture runs on whichever grep the author has, so the local suite is green by construction. Running on both platforms is the only detector. That is also why it is stated as an unconditional rule rather than a "when you have multiple files" caveat: "expect one file" is doing load-bearing work in the buggy version, and a single-entry list is exactly the trigger.
It sits beside the two BSD
datetraps because it is the same shape — an implementation-dependent default where the portable form costs one flag.Cost
None on the always-loaded surface.
shell-scripting.mdis path-scoped to**/*.shandscripts/**, so it loads only when shell is in play.check-context-engineering.py --strictstill exits 0.modified:/reviewed:bumped, per the frontmatter convention this repo's owncheck-docs-index.shCheck 5 enforces.