Tuesday, June 30, 2026

Brace enlargement tree


Right here’s a loopy bash one-liner I discovered through an article by Peter Krumins:

echo {w,t,}h{e{n{,ce{,forth}},re{,in,fore,with{,al}}},ither,at}

This prints 30 English phrases:

when, whence, whenceforth, the place, whereby, wherefore, wherewith, wherewithal, whither, what, then, thence, thenceforth, there, therein, subsequently, therewith, therewithal, thither, that, hen, therefore, henceforth, right here, herein, herefore, herewith, herewithal, hither, hat

This put up will clarify how the one-liner works.

Bash brace enlargement iterates via all prospects listed inside curly braces, with prospects separated by a comma. Word that the comma is a separator and never a terminator. And so, for instance, the expression {w,t,} is successfully {w,t,""}.

When bash sees two brace expressions, these develop to the cartesian product of the 2 expressions. For instance,

echo {A,B}{1,2,3}

produces

A1 A2 A3 B1 B2 B3

Within the expression above we’ve

{w,t,}h{e…,ither,at}

So the enlargement will enumerate all prospects of {w,h,} multiplied by all prospects of {e…,ither,at} the place e… is itself a brace expression.

A diagram will assist so much.

The brace enlargement does a depth-first traversal of this tree.

Related Articles

Latest Articles