Bash script generator for safe, commented shell scripts
Shell scripts that rename, back up or clean files can do a lot of damage with one unquoted variable. Tell your todo.is agent what the script should do and where it runs. It writes a careful, commented bash script, tests it in a throwaway folder in its workspace, and explains how to run and schedule it.
The prompt
- Write a bash script that [WHAT THE SCRIPT SHOULD DO]. It runs on [SYSTEM] as [USER OR PERMISSIONS]. Inputs: [ARGUMENTS OR PATHS]. Use set -euo pipefail, quote every variable, add a --dry-run flag, log what it does with timestamps, and exit with a clear message on errors. Test it in your workspace on a fake folder that looks like mine, check it with ShellCheck, and send me the .sh file with usage notes and a cron line to run it [HOW OFTEN].
What to change
- [WHAT THE SCRIPT SHOULD DO]: E.g. "back up /var/www and the MySQL dump to a dated .tar.gz and delete backups older than 14 days".
- [SYSTEM]: E.g. "Ubuntu 24.04 server", "macOS with zsh as my shell", "Raspberry Pi OS", "Git Bash on Windows".
- [USER OR PERMISSIONS]: E.g. "root via sudo" or "a normal user without sudo".
- [ARGUMENTS OR PATHS]: E.g. "source folder and backup folder as arguments" or "fixed paths inside the script".
- [HOW OFTEN]: E.g. "every night at 2:30", "every Sunday", or "never, I'll run it by hand".
Example result
- backup.sh: nightly site backup
- Creates /backups/site-2026-10-08.tar.gz with /var/www and a database dump, then deletes backups older than 14 days.
- Usage
- • Preview: sudo ./backup.sh --dry-run
- • Run: sudo ./backup.sh
- • Schedule (crontab -e as root): 30 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
- Key parts of the script
- !/usr/bin/env bash
- set -euo pipefail
- SRC="/var/www"
- DEST="/backups"
- KEEP_DAYS=14
- STAMP="$(date +%F)"
- DRY_RUN=false
- [[ $# -gt 0 && "$1" == "--dry-run" ]] && DRY_RUN=true
- log() { printf '%s %s\n' "$(date '+%F %T')" "$*"; }
- run() { if $DRY_RUN; then log "DRY: $*"; else "$@"; fi; }
- [[ -d "$SRC" ]] || { log "Source $SRC not found"; exit 1; }
- mkdir -p "$DEST"
- run mysqldump --single-transaction shopdb > "$DEST/db-$STAMP.sql"
- run tar -czf "$DEST/site-$STAMP.tar.gz" "$SRC" "$DEST/db-$STAMP.sql"
- run rm -f "$DEST/db-$STAMP.sql"
- run find "$DEST" -name 'site-*.tar.gz' -mtime +"$KEEP_DAYS" -delete
- log "Backup finished: $DEST/site-$STAMP.tar.gz"
- Why it's written this way
- • set -euo pipefail stops on the first error, on unset variables and on failed pipes
- • Quoted variables keep paths with spaces from splitting into two
- • run() wraps every command that changes something, so --dry-run is a true preview
- • find -mtime +14 -delete only touches files named site-*.tar.gz in the backup folder
- Test results
- • Dry run printed 4 planned commands, created nothing
- • Real run on a fake /var/www (1,200 files) made a 38 MB archive that extracts cleanly
- • ShellCheck 0.10: no warnings
- • Note: put database credentials in /root/.my.cnf (chmod 600), not in the script
How to do it with todo.is
- Copy the prompt and describe the job, the system and the inputs.
- Send it in todo.is or by message to your agent. Paste an ls -la or folder tree if the layout matters.
- Your agent writes the script, tests it in a sandbox folder and runs ShellCheck.
- Download the .sh file, read the notes, and try --dry-run on your machine first.
- Paste any error output back and it fixes the script.
Tips for a better result
- Say the exact system. GNU and macOS tools differ: sed -i, date -d and readlink -f behave differently on a Mac.
- Always try --dry-run first on a real machine, especially for anything with rm, mv or find -delete.
- Cron runs with a minimal PATH and no environment. Use full paths or set PATH at the top of the script.
- Keep passwords out of the script; use a config file with tight permissions or environment variables.
- Ask your agent to add a message to you on failure, e.g. a curl to a webhook, if the job is important.
bash script generator: FAQ
- Can it run the script on my server? No. It tests the script in its own workspace on a fake folder that mirrors yours. You copy the script to your machine and run it there.
- What does set -euo pipefail do? -e exits on any failed command, -u treats unset variables as errors, and -o pipefail makes a pipeline fail if any part fails. Together they stop a script from carrying on after something went wrong.
- Will the script work in zsh or sh? It's written for bash. Run it with bash explicitly or keep the #!/usr/bin/env bash line. Ask for a POSIX sh version if you need it on minimal systems.
- How do I schedule a bash script? On Linux and macOS use cron (crontab -e) or systemd timers. Your agent includes the exact line; the cron expression generator prompt explains schedules in detail.
JavaScript is required to use the todo.is app.