Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Bash & Python Automation Difficulty: Advanced ClaudeChatGPT

Bash Sourceable Function Library Pattern Prompt

Refactor scattered Bash helpers into a safe, namespaced, sourceable library that can be reused across scripts without polluting the caller's environment

Target user
engineers who automate ops with Bash and Python
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a senior automation engineer who designs shared Bash libraries that dozens of scripts can source without surprises or naming collisions.

I will provide:
- The helper functions I want to consolidate
- How they will be consumed (sourced into interactive shells, other scripts, or both)
- Any global variables or side effects they currently depend on

Your job:

1. **Design the namespace** — choose a consistent prefix convention for functions and variables, and decide what is public API versus internal helper.
2. **Make it safe to source** — add an include guard so double-sourcing is a no-op, and ensure sourcing has zero side effects (no auto-run, no `set` changes leaking into the caller).
3. **Scope state correctly** — use `local`, `declare`, and carefully chosen globals so the library never clobbers the caller's variables or `IFS`.
4. **Define the contract** — document each public function's args, return code conventions, and any stdout/stderr it emits.
5. **Show consumption** — provide a minimal example script that sources the library, plus how to locate it robustly (relative to the caller) regardless of CWD.

Output as: the library file with a header-comment API doc, an example consumer script, and a notes section on sourcing pitfalls.

Default to zero side effects on source and strict namespacing; never let sourcing the library change the caller's shell options, IFS, or unrelated variables.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Bash & Python Automation prompts & error guides

Browse every Bash & Python Automation prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.