P
💻DeveloppementIntermediateAll AIs

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)

Personalize this prompt with Léa

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

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

Automate file or database backups and rotationsCreate deployment scripts for web applicationsWrite system monitoring scripts with alertsAutomate server configuration and provisioning

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 Optimizer

Comments

  • 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

💻DeveloppementIntermediateChatGPT

ChatGPT Prompt for Generating Python Code

ChatGPT has become an indispensable tool for Python developers, whether beginners or experienced. Thanks to its advanced understanding of natural language, it can transform a functional description into clean, structured, and functional Python code in seconds. But the quality of the generated code depends directly on the quality of the prompt used. A vague prompt will produce generic and often unusable code, while a well-structured prompt will generate production-ready code with error handling, typing, and documentation. In this guide, we provide optimized prompts to get the most out of ChatGPT for generating Python code. Whether you need to write an automation script, a REST API, a data processing algorithm, or a complex class, these prompts will help you obtain precise and professional results. The goal is to save you time while maintaining a high level of quality, guiding ChatGPT with the right instructions so that it respects PEP 8 conventions, includes docstrings, and produces maintainable code.

0452
💻DeveloppementIntermediateAll AIs

Implement Kubernetes network policies

Secure Kubernetes networking

0325
💻DeveloppementIntermediateAll AIs

Automate Your Git Commits with AI

This prompt analyzes a Git diff and automatically generates structured commit messages following project conventions, with atomic splitting if needed.

0559
💻DeveloppementIntermediateAll AIs

Create effective mocks and stubs

Isolate tests from external dependencies

0292