How to use LLM in a script shebang
Key point
Introduced a way to run the LLM CLI like a script by putting it in the shebang line.
Details
Using LLM fragments, you can write #!/usr/bin/env -S llm -f followed by a single plain sentence and run it immediately. The simplest approach is to place the prompt itself right under the shebang.
Attaching a tool like -T llm_time also lets you generate a haiku that references the current time. With -t, you can run a YAML template directly while defining Python functions as tools.
- Uses gpt-5.4-mini with a system prompt instructing it to use calculation tools.
- Registers
add(a: int, b: int)andmultiply(a: int, b: int)as functions. - Running
./calc.sh 'what is 2344 * 5252 + 134' --tdlets you see the order of tool calls.
In the example, multiply first produced 12310688, and then add calculated 12310822. Finally, a more complex example was presented that extends this by connecting the Datasette SQL API as a tool, enabling Q&A over blog content.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.