Skip to content
TopicTracker
来自 johndcook.com查看原文
译文语言译文语言

花括号展开树

John D. Cook 分享了一个疯狂但巧妙的 bash 单行命令:echo {w,t,}h{e{n{,ce{,forth}},re{,in,fore,with{,al}}},ither,at},该命令利用花括号展开(brace expansion)机制一次性生成 30 个英语单词。文章通过将这个表达式可视化为树形结构,直观解释了花括号展开的工作原理:花括号内的逗号分隔选项会在树的分叉处进行排列组合,从而生成所有可能的单词。这种方法展示了 bash 语法中鲜为人知但极具表现力的特性。

背景速读

- **Brace expansion** 是 Bash 等 shell 中的一个功能:用 `{a,b,c}` 这样的语法让 shell 自动生成多个字符串组合,例如 `echo {a,b}{1,2}` 会输出 `a1 a2 b1 b2`。 - **John D. Cook** 是一位知名数学/编程博主,经常写关于数学、统计、编程语言冷知识和趣题的短文章。 - 文中的 **Peter Krumins** (aka "pkrumins") 是资深程序员,以编写《Bash 技巧》系列和分析开源代码著称。 - 该命令行本质上是用嵌套的 brace expansion 批量生成英语中以 "wh-"/"th-"/"h-" 开头的指示代词和副词(如 when/where/there/hence 等),展示了 brace expansion 可以像树状语法一样递归展开。理解这条命令需要对 Bash 展开顺序有基本认识:brace expansion 发生在变量替换和通配符展开之前。

相关报道

  • A financial expert warns that the current global economic instability could surpass the 2008 financial crisis, citing much higher levels of debt, weaker growth, and limited policy tools available to governments and central banks to respond effectively.

  • The article discusses the author's exclusive report on OpenAI's audited financials for 2024-2025, revealing that the company spent $34 billion while generating only $13.07 billion in revenue, sparking debate about the sustainability of such spending in the tech industry.

  • The article announces a new platform designed to give retail investors access to Wall Street-grade tools, including real-time breakout detection, AI stock predictions, and institutional buying data, all at a lower cost than traditional professional terminals.

  • The article argues that progress in AI development is decelerating, challenging the narrative of rapid and continuous advancement in the field.