Write Bash Scripts with AI

To write a bash script with AI, describe the task to @vustbot in Telegram — inputs, target OS, what should happen on failure — and ask for a commented script with strict-mode error handling. You copy the result into your terminal yourself: the bot writes the script, it never runs anything on your machine.

Bash is the language everyone uses and nobody remembers — the find flags, the quoting rules, the trap syntax. That makes it a strong fit for a chat model, as long as you state the environment and read the result before running it.

Open @vustbot in TelegramPay per action · no signup beyond Telegram

What the AI does in this scenario

  • Task description → commented, strict-mode script in one message
  • Names its assumptions: GNU vs BSD tools, required binaries, root or not
  • Regenerate with a second model (GPT-5-class, Claude, Gemini) when the first take is clumsy
  • Explains any line back to you in the same chat before you run it
  • Per-action sparks — no CLI-tool subscription for a script a month

Worked example: write bash scripts with ai

Input

Task: rotate logs for /var/log/myapp on Ubuntu — gzip *.log files older than 7 days, delete .log.gz archives older than 30 days, print everything touched. Must be safe to re-run.

Output

#!/usr/bin/env bash set -euo pipefail LOG_DIR="/var/log/myapp" # compress logs untouched for 7+ days (the -name '*.log' filter keeps .gz files out of gzip) find "$LOG_DIR" -maxdepth 1 -name '*.log' -mtime +7 -print -exec gzip {} \; # drop archives older than 30 days find "$LOG_DIR" -maxdepth 1 -name '*.log.gz' -mtime +30 -print -delete

How to write bash scripts with ai — step by step

  1. 1
    Describe the task and the environment

    One message to @vustbot: what the script must do, the OS (Ubuntu vs macOS changes the find and sed flags), and what should happen on failure. Environment omitted is the #1 source of broken output.

  2. 2
    Ask for strict mode and comments

    Request "set -euo pipefail, a comment per non-obvious line, and no silent failures". A script that dies loudly at the first bad step is debuggable; one that half-runs is not.

  3. 3
    Read it, dry-run it, then run it

    Paste any line you don't understand back into the chat and ask what it does. Run with echoed commands or on a scratch directory first — the bot cannot test the script for you, so this step is yours.

AI vs doing it manually

Honest take: for the classic one-liners — "find files older than N days", "loop over lines in a file" — a Stack Overflow answer or your own snippets file is often faster and already battle-tested; generation earns nothing there. AI wins when the task is a combination no one has posted verbatim: your directory layout, your retention rules, your logging format, stitched into one script with error handling you'd otherwise skip. It also wins the explain-back step — asking "what does this trap line do" beats reverse-engineering someone's 2014 forum answer.

The prompt to copy

Write a bash script that [TASK]. Target OS: [UBUNTU/MACOS/ALPINE]. Inputs: [FILES/ARGS/ENV VARS]. On failure: [STOP AND EXIT/LOG AND CONTINUE]. Requirements: set -euo pipefail; quote all variable expansions; comment each non-obvious line; list any assumptions (required binaries, permissions) at the top.

Frequently asked questions

Related in Developers

Try it on your real task

The welcome bonus covers a first run — send the prompt above with your own facts and judge the output yourself.

Open @vustbot