2 hours ago · Writing · hide · 0 comments

Here’s a crazy bash one-liner I found via an article by Peter Krumins: echo {w,t,}h{e{n{,ce{,forth}},re{,in,fore,with{,al}}},ither,at} This prints 30 English words: when, whence, whenceforth, where, wherein, wherefore, wherewith, wherewithal, whither, what, then, thence, thenceforth, there, therein, therefore, therewith, therewithal, thither, that, hen, hence, henceforth, here, herein, herefore, herewith, herewithal, hither, hat This post will explain how the one-liner works. Bash brace expansion iterates through all possibilities listed within curly braces, with possibilities separated by a comma. Note that the comma is a separator and not a terminator. And so, for example, the expression {w,t,} is effectively {w,t,""}. When bash sees two brace expressions, these expand to the cartesian product of the two expressions. For example, echo {A,B}{1,2,3} produces A1 A2 A3 B1 B2 B3 In the expression above we have {w,t,}h{e…,ither,at} So the expansion will enumerate all possibilities of…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.