Skip to content

Published shell snippets: <placeholder> parses as redirection, 155 lines are one edit from failing silently, and bash -n gates it backwards #306

Closed

Description

@atrawog

What was found

<placeholder> text inside a fenced shell block is parsed by bash as redirection, not as a placeholder. Two published guards in internals/skills/git-workflow/references/evidence-and-freshness.md were found to be unrunnable this way — discovered only because a validator executed them. They are fixed in opencharly/plugins#203.

The corpus-wide picture, measured on plugins@origin/main:

402  fenced shell blocks across 147 files
2089 lines inside those fences
181  lines carrying an angle-bracket placeholder
     155  LOUD    some bracket lacks a redirect target -> bash refuses to parse
      26  SILENT  every bracket has a target -> the line RUNS, wrongly

Why most of it is safe, and why that is not reassuring

Bash parses an entire line before executing any of it, so a syntax error anywhere prevents the earlier redirection from ever being performed. One malformed placeholder immunises the whole line.

rm <artifact-repo>/<suspect-path>        '>' -> newline    syntax error      LOUD
grep -o x CHANGELOG/<entry>.md           '>' -> '.md'      parses, runs      SILENT

So safety is a property of the line, not of any bracket — and it is an accident of how the line happens to end, not a design decision.

The part that makes this worth filing: it decays under normal maintenance

Appending one token flips a safe line into a dangerous one. Executed:

BEFORE  rm <artifact-repo>/<suspect-path>       -> syntax error near `newline`, refuses to parse
AFTER   rm <artifact-repo>/<suspect-path>.bak   -> PARSES AND RUNS
        stdout: ''                              <- a `for x in $(...)` loop iterates ZERO times
        stderr: 'artifact-repo: No such file or directory'

An author adding an extension, a suffix, or a flag value converts a self-announcing failure into a silently-empty one. There is no diff signal, no gate, and the line looks more complete afterwards. 155 lines are one ordinary edit away from the dangerous class.

Because the protection comes from the line's parse as a whole, the edit and the bracket providing the protection need not be anywhere near each other.

The failure mode is the empty-set problem

The error goes to stderr; the empty result goes to stdout. A caller of the shape for sha in $(...) consumes stdout, iterates zero times, and reads as "nothing found — clean." A reader who glanced at the terminal would see an error message and still get a passing check.

THE OBVIOUS GATE IS EXACTLY BACKWARDS

bash -n over every fenced block fails the 155 safe lines and passes the 26 dangerous ones, because the dangerous ones are precisely those that parse. Anyone building this check should know that before writing it.

A gate that works has to detect the placeholder pattern inside a fence, not unparseable shell — or better, distinguish blocks meant to be run as given from templates a reader edits before running, since angle brackets are conventional and correct in the second case.

What is NOT claimed

26 lines run; only three are shown to produce a false verdict (the guards, fixed in plugins#203). Several of the rest are comments, and most are templates where execution produces visible nonsense. Running wrongly and reading as a pass are different, and only the second is a defect. The population is measured; the defect rate outside those three is not.

Related

  • opencharly/plugins#203 — fixes the three guard lines
  • The two guards were found by execution during review. Prose review cannot execute, so every other published command in the corpus is unverified by construction until someone runs it.

Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)

Activity

  1. atrawog commented on Aug 18, 2026

    @atrawog
    ContributorAuthor

    Correction — the three header totals are undercounts. Cause found, and it is not the ref.

                              issue body    correct
    fenced shell blocks           402         408
    files containing them         147         148
    lines inside those fences    2089        2123
    

    Cause: my scan anchored fences at column zero. The pattern was ^```(bash|sh|shell|console), which silently drops every fence indented inside a list item or blockquote.

    indented shell fences the ^ anchor missed:  6
    402 + 6 = 408
    

    Ruled out by measurement rather than assumed:

    ref            origin/main at c4aa221, unmoved since the scan — my totals reproduce exactly at 402/147
    .mdx files     0 in the corpus; md+mdx+markdown == .md == 549 files, so the file filter is not it
    fence set      widening to zsh/shell-session/`bash …` changes nothing; census shows ```bash 399 + sh/shell/console
    

    A collaborator suspected a main-vs-origin/main gap — a real defect that had bitten them earlier the same night — and explicitly declined to state it as the cause without reproducing it. That was the right call: the ref was not the cause, and a plausible recent mechanism would have been the wrong diagnosis.

    What this changes

    The corrected totals are larger, so the exposure is slightly wider, not narrower. Nothing in the analysis depends on them: the 181 / 155 / 26 split, the parse-whole-line mechanism, the executed BEFORE/AFTER transition, the inverted-bash -n finding, and every stated limit were all measured separately and stand unchanged.

    But they are the first numbers a reader meets, which is exactly why they needed to be right.

    The lesson, since this issue is about instruments

    A ^ anchor encodes an assumption about the FORM of what you are looking for — here, that a fence begins at column zero. Fences indented under a list item are ordinary markdown and their contents are just as copy-pasteable.

    Same class as the defect this issue documents: a pattern that silently matches less than intended, returning a confident number with no signal that anything was skipped.

    Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)

  2. atrawog commented on Aug 18, 2026

    @atrawog
    ContributorAuthor

    Two additions: a sharper scope for the hazard, and a third failure mode that depends on the reader's shell

    1. The dangerous property is narrower than "a placeholder in a fence"

    The property that matters is a placeholder inside $(…) whose output is consumed as a verdict — typically feeding a for loop. That is what converts a failed command into an empty set, which reads as a clean pass.

    for sha in $(grep -ohE '...' CHANGELOG/<entry>.md); do ... done
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ fails -> empty -> loop body never runs -> "clean"
    

    This is actionable where "prose review cannot execute" is only true. It tells a reader which snippets actually need running: not all 408 blocks, but the subset whose output is consumed rather than displayed. A placeholder in a command a reader edits and runs interactively is conventional and safe; a placeholder inside a substitution feeding a verdict is not.

    Credit: this narrowing came from the plugins#203 validator, not from the original filing.

    2. The same broken line fails three different ways, decided by the reader's grep

    Measured, not predicted — all three from one fixture with two CHANGELOG entries present:

    GNU grep, no file named 'entry'    stderr error, stdout EMPTY        -> loop runs 0x -> reads CLEAN
    GNU grep, a file named 'entry'     "Is a directory", stray .md       -> stdout EMPTY -> reads CLEAN
    a RECURSING grep (e.g. ugrep)      returns SHAs from EVERY entry     -> loop runs -> PLAUSIBLE WRONG ANSWER
    

    The third is the worst: the guard does not fail at all. It silently widens from one file to the whole directory and returns a well-formed answer to a question nobody asked — output a reader would trust, from a command that is not doing what it says.

    grep being a shell function that reroutes to a recursing implementation is not exotic — it is the case in at least one environment where this corpus is actively maintained.

    Consequence for anyone auditing this: a snippet's behaviour is not a property of the snippet alone. Two reviewers running the same published line can get an error, an empty result, and a confident wrong answer, and none of them is wrong about what they saw.

    Scope note on the audit itself

    The corpus counts in this issue were re-derived through /usr/bin/grep and are unchanged (402 pre-correction, 408 corrected) — every measurement piped stdin, and the recursion difference only manifests when a directory is passed as an argument. Audits that pass path arguments to a bare grep should be re-checked; ones that pipe are unaffected.

    Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)

  3. atrawog commented on Aug 18, 2026

    @atrawog
    ContributorAuthor

    CORRECTION to the previous comment — the third case does NOT produce a wrong answer. It produces a clean pass and a stray file.

    The prior comment claimed:

    a RECURSING grep (e.g. ugrep) → returns SHAs from EVERY entry → loop runs → PLAUSIBLE WRONG ANSWER

    That is wrong, and the wrong half is the one that mattered. Executed as published, with a recursing grep live, inside the for loop it is written for:

    for sha in $(grep -ohE '[0-9a-f]{7,40}' CHANGELOG/<entry>.md); do ... done
    
      loop iterations: 0
      stray .md exists, containing:
          9f8e7d6c5b4a
          a1b2c3d4e5f6
    

    The recursion is real — grep does search every entry — but the same > that made the line parse diverts the output into the stray .md file. So $( ) captures nothing, the loop body never executes, and the answer is written to a file nobody reads.

    The corrected table: every case reads as clean

    GNU grep, no file named 'entry'    stderr error, stdout EMPTY                     -> reads CLEAN
    GNU grep, a file named 'entry'     "Is a directory", stray .md                    -> reads CLEAN
    a RECURSING grep                   searches everything, output diverted to .md    -> reads CLEAN
                                       + leaves a file containing the real answer
    

    This is a tidier and more damning finding than the one it replaces: there is no environment in which this guard reports a problem. The third case is the worst not because it lies, but because it silently produces the correct answer into a file the reader will never open.

    How I got it wrong, since this issue is about instruments

    I tested a simplification. To isolate the recursion I dropped the redirect — grep -ohE '…' CHANGELOG/ — and it printed the SHAs on stdout. I then reported that as the behaviour of the full line.

    The part I removed to isolate the mechanism was the part that made the output invisible. Isolating a mechanism removes the interaction that matters.

    A scoping fact that decides who is actually exposed

    bash script.sh   non-interactive shell, function never loaded  -> GNU behaviour
    pasted           interactive shell, function live              -> recursing behaviour
    

    A reader who saves the snippet to a file gets one behaviour; a reader who pastes it gets another — and pasting is how a published snippet is actually used. This is invisible to anyone testing via a script file, which is why three script-file tests found no recursion and a pasted test found it immediately.

    This is the third correction to this issue. The 181 / 155 / 26 split, the parse-whole-line mechanism, the BEFORE/AFTER transition and the inverted-bash -n finding are unaffected — all were measured directly rather than inferred.

    Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)

  4. atrawog commented on Aug 18, 2026

    @atrawog
    ContributorAuthor

    Anchor correction — the figures were pinned to a moving ref

    The body says the corpus counts were "measured on plugins@origin/main". origin/main is not a re-derivable anchor — it named c4aa221 at filing and names 01edd45 now, and one of the intervening merges changed the very file this issue is about.

    Re-derived at today's main, the headline figures are unchanged:

                          at filing (c4aa221)   at 01edd45   
    fenced shell blocks          408               408
    files containing them        148               148
    

    So nothing here is stale. The defect is the anchor, not the numbers — and it was invisible precisely because the numbers held. Had they drifted, the moving ref would have announced itself as a discrepancy.

    Read every figure in this issue as measured at plugins@c4aa221 and charly@7c538cb9, and re-derive at those shas rather than at main.

    The general form, which this issue's own subject matter argues for: a measurement anchored to a fixed tree survives the artifact changing around it. A reader re-runs it at the sha and gets the stated number; a later different number is then a second consistent fact rather than a discrepancy to reconcile. An anchor to origin/main gives up that property for nothing.

    Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system)

  5. atrawog commented on Aug 28, 2026

    @atrawog
    ContributorAuthor

    Validation (2026-08-28) — RESOLVED

    Verified against current marketplace main. The two unrunnable guards were fixed (plugins#203), and the corpus was regenerated: evidence-and-freshness.md no longer contains the rm <...> / grep -o x CHANGELOG/<entry>.md shapes (the file now has only 8 angle-bracket characters total, none in the LOUD/SILENT redirection class).

    Closing as resolved.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions