DEV Community

Cover image for The number that changed shells
Oroboro Labs
Oroboro Labs

Posted on Originally published at oroborolabs.github.io

The number that changed shells

The declarator from the last post had one debut left in it. Measuring a count for the previous field note, it was handed a command with a caret anchor — ^, match-the-start-of-line — and it measured ninety-two. The author, checking by hand in a different terminal, measured eighty-six. Same command. Same files. Same disk. The declarator had been told to run everything twice and demand the same integer; it did, and it got ninety-two twice — because both runs used the same shell.

The culprit is a quiet rule of cmd.exe: outside quotes, a caret is an escape character, and a lone caret at the edge of a pattern simply vanishes. The anchor never reached grep. Bash passed it through untouched. So one shell counted every line containing the pattern, and the other counted only the lines starting with it — six phantom matches, silently, in a tool whose entire job is counting.

A number that depends on the shell is not a number

The repair extends the same discipline one level down. The guard already refused hand-typed digits; now it refuses shell-dependent commands too. Every declared count runs in both shells — cmd.exe and bash — and the two must agree on the same integer before anything is written or pushed. A command that is mute in either shell is treated as disagreement, not as zero, because a count you can only hear in one room is a count you cannot audit. Divergence aborts with both numbers and the name of each shell, so the next reader inherits the diagnosis, not just the refusal.

There is a second lesson folded inside the first: the acceptance test for the shell-ambiguity guard had to run through both shells to mean anything. A test executed in a single environment certifies the command for that environment and nothing else — which is exactly how ninety-two stayed green for a quarter of an hour.

Two counts in this post were written by the declarator and agreed upon by both shells. The notes directory holds one hundred forty-two HTML pages, and the instrument directory holds twelve tools of the counting family — the e150s, guards and senders and thermometers grown one defect at a time.

What the acceptance proved

Red round first. A caret command through the guard: exit 2, SHELL_AMBIGUO, one hundred sixty-three versus zero, shell names in the receipt. A caret command through the declarator: exit 2 again, thirty-two versus three — because echo 3^2 prints 32 in one shell and 3^2 in the other, the divergence reduced to its smallest honest seed. Then the green round: a plain glob-and-count command, same integer from both shells, and the previous field note — whose counts predate this repair — re-run through the new guard, both numbers still standing in cmd.exe and bash alike. The regression suite that guards the catalog of instruments stayed green throughout.

One hundred forty-one and eighty-six were the numbers the last post carried out; this one adds the property that makes them durable: they no longer belong to whichever terminal happened to be open.

Field notes from a one-person automation workshop. Every number here comes from a receipt on disk.

Top comments (0)