T
traeai
Sign in
返回首页
AI HOT 精选

Using LLM in the shebang line of a script

7.5Score
Using LLM in the shebang line of a script

TL;DR · AI Summary

Using LLM in the shebang line of a script is an innovative practice that enables more flexible command execution and tool integration.

Key Takeaways

  • Using LLM in the shebang line can generate SVG images.
  • Combining tool calls allows creating poetry mentioning the exact current time.
  • Supports YAML template definitions for executing complex calculations.

Outline

Jump quickly between sections.

  1. Introduces the background of using LLM in the script shebang line.

  2. Demonstrates the simplest LLM shebang example.

  3. Shows how to enable tool calls via options.

  4. Demonstrates defining Python functions and executing calculations.

  5. Provides a complex case combining Datasette SQL API.

Mindmap

See how the topics connect at a glance.

查看大纲文本(无障碍 / 无 JS 友好)
  • 在脚本的shebang行中使用LLM
    • 基本模式
      • 生成SVG图像
      • 工具调用
    • YAML模板定义
      • 定义Python函数
      • 执行复杂计算

Highlights

Key sentences worth saving and sharing.

#LLM#Shebang#CLI Tools#Script Programming
Open original article

TIL: Using LLM in the shebang line of a script

[Simon Willison’s Weblog](https://simonwillison.net/)

Subscribe

Sponsored by:WorkOS — Make your app Enterprise Ready with SSO, SCIM, RBAC, and more.

11th May 2026

Image 1: None

TILUsing LLM in the shebang line of a script— This comment on Hacker News inspired me to investigate patterns for using my LLM CLI tool in a shebang line:

Kim_Bruning on Hacker News:

But seriously, you can put a shebang on an english text file now (if you're sufficiently brave) [...]

This inspired me to look at patterns for doing exactly that with LLM. Here's the simplest, which takes advantage of LLM fragments:

code
#!/usr/bin/env -S llm -f
Generate an SVG of a pelican riding a bicycle

But you can also incorporate tool calls using the -T name_of_tool option:

code
#!/usr/bin/env -S llm -T llm_time -f
Write a haiku that mentions the exact current time

Or even execute YAML templates directly that define extra tools as Python functions:

#!/usr/bin/env -S llm -t model: gpt-5.4-mini system: | Use tools to run calculations functions: | def add(a: int, b: int) -> int: return a + b def multiply(a: int, b: int) -> int: return a * b Then:

code
./calc.sh 'what is 2344 * 5252 + 134' --td

Which outputs (thanks to that --td tools debug option):

code
Tool call: multiply({'a': 2344, 'b': 5252})
  12310688

Tool call: add({'a': 12310688, 'b': 134})
  12310822

2344 × 5252 + 134 = **12,310,822**

Read the full TIL for a more complex example that uses the Datasette SQL API to answer questions about content on my blog.

Posted 11th May 2026 at 6:48 pm

Recent articles

This is a beat by Simon Willison, posted on 11th May 2026.

ai 2014generative-ai 1785llms 1751llm 598llm-tool-use 68

Monthly briefing

Sponsor me for $10/month and get a curated email digest of the month's most important LLM developments.

Pay me to send you less!

Sponsor & subscribe

AI may generate inaccurate information. Please verify important content.