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
Stable Diffusion Prompt to Create a Software Architecture
Stable Diffusion offers fascinating possibilities for visualizing abstract concepts like software architecture. By combining precise technical terms with suitable visual directives, it becomes possible to generate stylized diagrams, infrastructure schemas, and visual representations of complex systems. Whether you are a developer looking to illustrate technical documentation, a software architect preparing a presentation, or a trainer aiming to make abstract concepts tangible, Stable Diffusion can transform your text descriptions into impactful visuals. The tool particularly excels at creating conceptual illustrations showing interactions between components, data flows, and abstraction layers. While Stable Diffusion does not replace traditional UML diagramming tools, it brings an artistic and instantly understandable dimension to your architectures, ideal for executive presentations, technical blog posts, or training materials. The key lies in crafting prompts that balance technical precision with visual vocabulary the model masters.
Implement pipeline as code testing
Test CI/CD pipelines
Design a Complete REST API
Design a robust and well-structured REST API with OpenAPI documentation, error handling, and security best practices.
Learn Git Basics for Beginners
Learn Git from scratch with illustrated explanations, concrete examples, a practical workflow, and an essential commands cheatsheet.