A neural network for writing scripts: Bash, PowerShell and Python
A model writes scripts for routine fast, but running them blindly is risky. How to state the task, demand a safe dry-run mode and check the result before launch.
5 min · · development · автоматизация
A neural network for writing scripts shines where the task is clear and recalling the syntax is a chore: move files by a rule, rename a batch, build a report from logs, sort data into folders. A model produces a working draft in minutes. The danger is elsewhere: a script that deletes or overwrites something can damage data because of a mistake in one line. Below: how to state the task to get safe code, how to demand a dry-run mode, which Bash, PowerShell and Python examples come out and how to check the result before running.
A neural network for writing scripts: how to state the task
A vague "write a script to clean logs" gives a script for imaginary conditions. A good request has six parts:
- Environment. OS and shell version: "macOS 14, bash 3.2" or "Windows PowerShell 5.1", "Python 3.11".
- Task. What goes in and what must come out, with example file names.
- Boundaries. Which folders may be touched and which may not.
- Safety. Dry-run by default, real actions only with an explicit flag.
- Error behaviour. Stop or skip, what to write to the log.
- Answer format. One file, no explanations inside the code, and after the code a list of the places where the script changes data.
An example of a ready request:
Write a Bash script.
Environment: macOS 14 and Ubuntu 22.04.
Task: in the folder given as the first argument find *.log files older than N days
(N is the second argument, default 30) and move them to an archive subfolder.
Do not touch nested folders.
Constraints: no sudo, delete nothing, only move.
Dry-run by default: print what would be done. Real moves only with the --apply flag.
Validate arguments, use set -euo pipefail, handle spaces in file names.
After the code list the commands that change the file system and what could go wrong.The last line is essential: it makes the model name the dangerous places itself, and you compare its list with the code.
Bash: a script with dry-run
Here is the result of such a request, refined and checked by hand:
#!/usr/bin/env bash
## Moves .log files older than N days to the archive subfolder. By default it only shows what it would do.
set -euo pipefail
usage() { echo "Usage: $0 FOLDER [DAYS] [--apply]" >&2; exit 1; }
DIR="${1:-}"; [[ -n "$DIR" ]] || usage
DAYS="${2:-30}"
APPLY="${3:-}"
[[ -d "$DIR" ]] || { echo "No such folder: $DIR" >&2; exit 1; }
[[ "$DAYS" =~ ^[0-9]+$ ]] || usage
count=0What is done right here: -print0 and read -d '' survive spaces in names, mv -- does not confuse a file name with an option, -maxdepth 1 does not descend into nested folders, and without the --apply flag nothing changes. Run it as ./cleanup.sh ~/logs 30, then ./cleanup.sh ~/logs 30 --apply.
PowerShell: -WhatIf for free
In PowerShell the safe mode is built in: if a script is declared with SupportsShouldProcess, it gets a -WhatIf parameter and you do not have to write a dry-run yourself.
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory)][string]$Path,
[int]$Days = 30
)
if (-not (Test-Path -LiteralPath $Path -PathType Container)) {
throw "No such folder: $Path"
}
$limit = (Get-Date).AddDays(-$Days)
$archive = Join-Path $Path 'archive'
$old = Get-ChildItem -LiteralPath $Path -Filter '*.log' -File |First run .\cleanup.ps1 -Path D:\logs -WhatIf, then without -WhatIf. If the script contains Cyrillic and you use Windows PowerShell 5.1, save the file as UTF-8 with BOM, otherwise strings may be read wrongly. Cyrillic and API requests from PowerShell are covered in the article PowerShell and the Claude API.
Python: argparse and an explicit flag
import argparse
import shutil
import time
from pathlib import Path
def main() -> None:
parser = argparse.ArgumentParser(description="Moves .log files older than N days to archive/")
parser.add_argument("folder", type=Path)
parser.add_argument("--days", type=int, default=30)
parser.add_argument("--apply", action="store_true", help="do it; without the flag only show")
args = parser.parse_args()
if not args.folder.is_dir():Python beats Bash when logic grows: date parsing, JSON, tables. Whatever language the neural network writes code in, the principle is the same: an explicit flag for the action and a list of affected files in the output.
How to check a script before running it
- Read it and ask for an explanation. Ask the model to explain line by line which commands change data. A gap between its explanation and your reading of the code is a reason to stop.
- Static analysis. For Bash,
shellcheck; for PowerShell, PSScriptAnalyzer; for Python,python -m py_compileand a linter such as ruff. They catch missing quotes and typos. These tools are installed separately; see their documentation. - A test on a copy. Create a temporary folder with a dozen files that reproduce your case, including names with spaces and Cyrillic.
- Dry-run on real data. Read the output. If the list contains something that should not be there, stop.
- The first real run on a small sample. And make sure a copy or snapshot of the data exists.
- Danger signs. Look in the code for
rm -rf,sudo,curl ... | bash,Remove-Item -Recurse -Force,chmod -R,find ... -delete, a>redirect onto an existing file and unquoted variables in paths. If you see any, make the model rewrite without it.
If the script is needed right in a project
When the task is tied to a repository, a terminal agent is more convenient: it sees the folder structure, creates the file itself, runs it on test data and fixes errors. Setup is described in the Claude Code guide. But keep command confirmation on: an agent that runs its own script without asking removes your last safety net. For your own request templates, the collection of prompts for programmers is handy.
If you want to get drafts from your own code, send the task to the API and save the result to a file without running it automatically:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.zukko.pro/v1",
api_key=os.environ["ZUKKO_API_KEY"],
)
task = open("task.txt", encoding="utf-8").read()
r = client.chat.completions.create(
model="claude-sonnet-5-5",
max_tokens=2000,
messages=[
{"role": "system", "content": "Reply with the code of a single file, no markdown fences, no explanations."},
{"role": "user", "content": task},
],
)
open("draft_script.sh", "w", encoding="utf-8").write(r.choices[0].message.content)
print("Draft saved to draft_script.sh. Read it before running.")This is the opposite task to the article Bash, curl and jq: there a script calls a model, here a model writes a script.
What it costs
Prices on October 18, 2026, per 1M tokens. A request describing the task is about 1,500 tokens, a script with explanations about 1,200 tokens.
claude-sonnet-5-5(input $0.4, output $2): 1,500 × 0.4 / 1,000,000 + 1,200 × 2 / 1,000,000 = 0.0006 + 0.0024 = $0.003. Ten rounds of edits, each with 3,000 input tokens: 10 × (3,000 × 0.4 + 1,200 × 2) / 1,000,000 = 10 × 0.0036 = $0.036.deepseek-v4.1-flash($0.013 / $0.038): 1,500 × 0.013 / 1,000,000 + 1,200 × 0.038 / 1,000,000 ≈ $0.00007 per request.
A script costs pennies. The price of a mistake in a script is incomparably higher, so do not skimp on checking. Current prices: GET https://api.zukko.pro/v1/models.
FAQ
Which model writes scripts best?
We do not claim that one writes better. A cheap model is enough for short scripts; for complex logic compare two or three on one task and check the result with tests.
Can I run a generated script right away?
No. Read it, run static analysis, run it in dry-run mode and on a copy of the data. It takes minutes and saves your data.
How do I make a model avoid dangerous commands?
Forbid them explicitly in the request: "no sudo, no rm, move only". But that does not replace checking: a model can break the constraint, so look for dangerous commands in the code yourself.
How do I connect from Russia?
Access from Russia goes through the gateway, payment by SBP, a MasterCard card or crypto. The key is created in the Zukko dashboard.
zukko
Pay 25×
less
for Claude Code & ChatGPT
One fetch_* key and base URL api.zukko.pro — for Cursor, Claude Code, Codex, and any SDK.
Related articles
- Translating subtitles with a neural network: SRT without broken timecodesThe main risk when translating SRT with a neural network is a broken file structure. A scheme where timecodes never reach the model, and a Python script with validation.
- Editing texts with a neural network: proofreading, style and cuttingDifferent kinds of editing need different prompts. Wording for proofreading, style and cutting, how to get edits with explanations and how not to lose the author's voice.
- Dify in Docker: installation, first-run setup and connecting modelsInstall Dify with Docker Compose, create the admin account and connect Claude, GPT and DeepSeek models on one key. Plus what to do when containers will not start.
- Regular expressions with AI: how to get a working regex and test itA model writes regex fast but errs confidently on edge cases. A request with examples, an auto-check loop and protection against hangs.