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 : 1. Commencer par un shebang approprié et un en-tête documentant l'objectif, l'auteur et la date 2. Utiliser `set -euo pipefail` pour une gestion stricte des erreurs 3. Définir les variables de configuration en haut du fichier, clairement commentées 4. Inclure une fonction `usage()` affichant l'aide avec les options disponibles 5. Parser les arguments avec `getopts` ou `getopt` selon la complexité 6. Implémenter une gestion des erreurs avec des messages explicites vers stderr 7. Utiliser un trap pour le nettoyage des fichiers temporaires à la sortie 8. Vérifier les prérequis (commandes nécessaires, permissions, fichiers d'entrée) 9. Utiliser des fonctions pour chaque bloc logique distinct 10. Inclure un mode verbose/debug activable par flag 11. Logger les actions importantes avec horodatage 12. 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)
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.
Learn more
Check the full skill on Prompt Guide to master this technique from A to Z.
View on Prompt Guide📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Similar Prompts
Generate Complete Technical Documentation for Your Code
A complete prompt to generate structured and professional technical documentation, adapted to the target audience and project type.
AI-Assisted Complete Code Review
A complete prompt to get an in-depth code review covering bugs, security, performance, readability, and best practices, with concrete fixes.
Legacy Code Refactoring
Safely and incrementally refactor legacy code following SOLID principles and modern best practices.
Create an Accessible React Component
Create fully accessible React components meeting WCAG 2.1 with keyboard navigation, ARIA, and screen reader support.