Using LLM in the shebang line of a script

Simon Willison's Blog Tools

Summary

Simon Willison demonstrates how to use the llm CLI tool in script shebang lines to execute LLM prompts and tool calls directly from executable files.

No content available
Original Article
View Cached Full Text

Cached at: 05/11/26, 10:50 PM

# TIL: Using LLM in the shebang line of a script Source: [https://simonwillison.net/2026/May/11/llm-shebang/](https://simonwillison.net/2026/May/11/llm-shebang/) Kim\_Bruning[on Hacker News](https://news.ycombinator.com/item?id=48073246#48090590): > 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](https://llm.datasette.io/en/stable/)\. Here's the simplest, which takes advantage of[LLM fragments](https://llm.datasette.io/en/stable/fragments.html): ``` #!/usr/bin/env -S llm -f Generate an SVG of a pelican riding a bicycle ``` But you can also incorporate[tool calls](https://llm.datasette.io/en/stable/tools.html)using the`\-T name\_of\_tool`option: ``` #!/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: ``` ./calc.sh 'what is 2344 * 5252 + 134' --td ``` Which outputs \(thanks to that`\-\-td`tools debug option\): ``` 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](https://til.simonwillison.net/llms/llm-shebang#templates-with-tools)that uses the Datasette SQL API to answer questions about content on my blog\.

Similar Articles

llm 0.32a0

Simon Willison's Blog

This article announces the release of version 0.32a0 of the 'llm' command-line tool by Simon Willison, providing a monthly briefing on LLM developments.

llm 0.31.1

Simon Willison's Blog

Release of llm 0.31.1, a command-line tool for interacting with large language models, by Simon Willison.

llm 0.32a3

Simon Willison's Blog

Release of llm 0.32a3, an alpha version of Simon Willison's command-line tool for interacting with large language models.

llama.cpp is the linux of llm

Reddit r/LocalLLaMA

The article draws a parallel between llama.cpp and Linux, positioning the open-source library as foundational infrastructure for running large language models.