Write Professional and Robust Bash Scripts
A comprehensive prompt to generate robust, professional Bash scripts with error handling, argument parsing and built-in best practices.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Tu es un expert en scripting Bash et en administration système Linux/macOS. Écris un script Bash complet pour réaliser la tâche suivante : [DESCRIPTION_DE_LA_TACHE].
Contexte d'exécution :
- Système cible : [SYSTEME_CIBLE ex: Ubuntu 22.04, macOS, CentOS, générique POSIX]
- Niveau de robustesse souhaité : [NIVEAU ex: script rapide, production, mission-critical]
Le script doit obligatoirement :
- Commencer par un shebang approprié et un en-tête documentant l'objectif, l'auteur et la date
- Utiliser
set -euo pipefailpour une gestion stricte des erreurs - Définir les variables de configuration en haut du fichier, clairement commentées
- Inclure une fonction
usage()affichant l'aide avec les options disponibles - Parser les arguments avec
getoptsougetoptselon la complexité - Implémenter une gestion des erreurs avec des messages explicites vers stderr
- Utiliser un trap pour le nettoyage des fichiers temporaires à la sortie
- Vérifier les prérequis (commandes nécessaires, permissions, fichiers d'entrée)
- Utiliser des fonctions pour chaque bloc logique distinct
- Inclure un mode verbose/debug activable par flag
- Logger les actions importantes avec horodatage
- Retourner des codes de sortie appropriés (0 succès, 1 erreur usage, 2 erreur exécution)
Pour chaque section du script, ajoute des commentaires expliquant le raisonnement. À la fin, fournis :
- Un exemple d'utilisation avec les commandes exactes
- Les pièges courants à éviter pour ce type de script
- Des suggestions d'amélioration (cron, systemd timer, intégration CI/CD)
Personalize this prompt with Léa
Answer 3 questions and Léa tailors the prompt to your situation.
Why this prompt works
<p>This prompt is designed to produce production-quality Bash scripts. By specifying <strong>the precise task</strong> and the <strong>target system</strong>, you get a script tailored to your environment. The prompt enforces essential best practices like <strong>set -euo pipefail</strong>, trap for cleanup, and argument parsing — elements often neglected in ad-hoc scripts.</p><p>To use it effectively, be as specific as possible when describing the task. For example, instead of "back up files", write "daily backup of /var/www to an S3 bucket with 30-day rotation and Slack notification on failure". The richer the context, the more relevant and complete the script will be.</p><p>You can adjust the <strong>robustness level</strong> to your needs: a quick script for prototyping will be more concise, while a mission-critical script will include advanced logging, locks to prevent simultaneous execution, and fine-grained signal handling. Feel free to iterate by requesting additions like <strong>external configuration file</strong> support, <strong>systemd</strong> integration, or <strong>automated tests with bats</strong>.</p>
Use Cases
Expected Output
A complete, commented Bash script, ready to use, with shebang, error handling, argument parsing, modular functions, usage examples and improvement recommendations.
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
- LéaAI
Pour les scripts mission-critical, ajoutez au prompt une demande de tests unitaires avec BATS (Bash Automated Testing System). Cela valide chaque fonction et évite les régressions avant déploiement.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Similar Prompts
NetworkPolicies for micro-segmentation
Isolate workloads with network policies
Prompt Claude to Create a Prototype
Creating a prototype is a crucial step in developing a product, application, or service. Traditionally, this phase requires a variety of technical skills, time, and often a multidisciplinary team. With Claude, you can significantly accelerate this process by generating functional prototypes from a simple description of your idea. Whether you want to design an interactive user interface, a web application mockup, an API prototype, or even a technical proof of concept, Claude can produce functional code, HTML/CSS wireframes, or complete architectures ready to be tested. The major advantage is Claude's ability to iterate quickly: you describe your vision, get a first prototype, then refine through successive exchanges until you get exactly what you're looking for. This approach democratizes rapid prototyping and allows entrepreneurs, designers, and product managers to validate their hypotheses without fully relying on a development team in the early stages of the project.
Optimize Slow SQL Queries
Analyze and optimize your slow SQL queries through execution plan analysis and precise index recommendations.
Sora Prompt for Debugging Code
Sora, OpenAI's video generation model, may seem like a surprising choice for debugging code. Yet its ability to produce dynamic visualizations opens up unique perspectives for understanding and resolving complex bugs. By generating visual representations of execution flow, data structures, or interactions between components, Sora allows developers to literally see their code's behavior. This visual approach is particularly effective for bugs related to user interfaces, animations, state transitions, or rendering issues. Instead of sifting through endless logs, you can ask Sora to create a video illustrating expected versus observed behavior, making problem identification easier. The prompts on this page guide you in using Sora for debugging, turning textual bug descriptions into clear visualizations that accelerate resolution. Whether you're working on front-end, visual algorithms, or complex data flows, these techniques help you adopt a visual debugging approach.