A finished shell script is not one with every feature you imagined. It is one you can run again from a clean folder, explain in under 200 words, and hand to someone else without a live demo. The last mile is mostly subtraction: stop adding, test a small set, document the edges, and package the result. Budget 45–60 minutes for this final pass, not another weekend. The goal is not a perfect script; it is a script you can run tomorrow without remembering what you did today.
Decide what “finished” means and freeze the scope
Before changing another line, write three acceptance criteria: one script, a maximum of three inputs, exit codes 0 for success, 1 for failure and 2 for usage, and a README under 200 words. If the criteria are not met, do not add a feature. Put extra ideas in next.txt, one item per line. Set a 25-minute timer for this freeze. Write the criteria on a sticky note or at the top of the script; if you cannot measure it, it is not a finish line. Anything that needs a new dependency, network call or second data file belongs in the next version. Your first release is version 0.1.
Run it from a clean folder
Make a new folder and copy in the script and one sample data file. Run bash -n script.sh to catch syntax errors, then ./script.sh sample.txt twice. The second run matters: it catches scripts that only work once. If it depends on files in the current directory, change the paths explicitly or cd to the script directory. A clean run should take under 2 minutes and produce the same output. If it cannot run with ./, use bash script.sh; then fix permissions with chmod 755 script.sh.
Add the smallest error handling that makes it safe
At minimum, check the argument count and the input file. Missing argument: print usage and exit 2. Missing file: print a clear message and exit 1. Successful run: exit 0. Quote variables: use "$file", not $file. If you use set -euo pipefail, understand what it does; otherwise explicit checks are safer for a first project. Do not add a logging framework, config file or colour output at this stage. Three checks are enough: argument, file, command success. Test each one separately so you see the exact message; a combined test can hide which guard failed.
Write a 6-line header and a 200-word README
Put a header at the top: purpose in one line, usage in one line, inputs in one line, outputs in one line, exit codes in one line, and last tested date in one line. Keep the README under 200 words: what it does, one install note, three example commands, and known limits. Include the version 0.1. That is enough for a first project. If a stranger cannot run it from the README in 5 minutes, fix the README before the code. Add chmod 755 so the executable bit is set.
Test five cases and record the results
Run exactly five: normal input, no arguments, missing file, filename with a space, and read-only or permission-denied file. Record pass or fail in test-notes.txt with the date; keep it under 20 lines. Give it 10–15 minutes. If four pass and one fails, fix only that issue and rerun all five. Do not start a sixth case unless it is a real bug. Five clean passes is your finish line.
Diagnose the classic last-mile failure
Symptom: the script works when you type commands in your terminal but fails when run from another folder, by another user or from a scheduler. Likely causes: relative paths, missing executable permission, environment variables not loaded, or interactive prompts waiting for input. The fix: run it from a fresh directory with bash -x script.sh sample.txt to see the failing line. Replace relative paths with explicit ones, remove prompts or add non-interactive defaults, and test with env -i only if you understand the environment. Check permissions with ls -l; 755 is usually right for a personal script. If it needs sudo or a password, stop and rethink the design.
Package and hand off a single folder
Create one folder named for the task and date, such as log-check-2025-06. Put in it: the script, README, one small sample input, and test notes. Name the sample input sample.txt so the README command is obvious. Compress only if you need to send it; an uncompressed folder is easier to inspect. Keep total size under 10 MB unless the sample data genuinely requires more. Make a second copy on another drive or in a personal backup folder. Cost should be £0: no paid tool is needed to finish this project. A second copy takes 2 minutes and prevents the most common “finished” script from disappearing.
Declare version 0.1 finished and record next steps
When five tests pass, the README runs in under 5 minutes, and no known failure remains, stop. Say it out loud: version 0.1 is finished. Wait 24 hours before adding features; this catches “just one more thing” creep. If you miss the 24-hour gap, set a calendar reminder; the point is to separate finishing from tinkering. Write three next-step ideas in next.txt, not in the script. If you want a bigger project later, create a new version number and a fresh test list. Finishing is a skill; repeat the same 45–60 minute close-out on the next script.
FAQ
How do I know when to stop adding features?
Stop when your three acceptance criteria pass and five test cases are clean. Any new idea goes to next.txt for a later version. A first script under 100 lines that works is more valuable than a half-finished 300-line script.
What if the script works but looks messy?
Messy is acceptable if it is readable and tested. Tidy only the names, indentation and error messages; do not refactor working logic during close-out. Spend 10 minutes maximum. Save a copy before any tidy-up, and rerun the five tests afterwards.
Do I need to publish or share my first script?
No. A finished first project can live in one folder with a README and two copies. Sharing is optional. If you do share it, remove personal paths, credentials and real data first; use the sample input instead.