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

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

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.

Learn more

Check the full skill on Prompt Guide to master this technique from A to Z.

View on Prompt Guide

Comments

Be the first to comment on this prompt.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Similar Prompts

💻DeveloppementIntermediateChatGPT

Write Integration Tests for an API

Create complete API integration tests with database setup, authentication, CRUD, and end-to-end scenarios.

29243
💻DeveloppementAdvancedClaude

Set Up Application Observability

Implement the three pillars of observability (logs, metrics, traces) with OpenTelemetry, Prometheus, and Grafana dashboards.

44239
💻DeveloppementIntermediateAll AIs

Generate Precise Regular Expressions with AI

This prompt generates precise and documented regular expressions, tailored to your programming language, with detailed explanations and built-in tests.

0172
💻DeveloppementIntermediateAll AIs

DALL-E Prompt to Generate JavaScript Code

DALL-E, the image generation model developed by OpenAI, is not designed to produce executable JavaScript code. However, it can play a valuable complementary role in a JavaScript developer's workflow. DALL-E excels at creating visuals related to development: user interface mockups, architecture diagrams, data flow schemas, or illustrations to document your code. By crafting precise prompts, you can obtain visual representations of complex JavaScript concepts like closures, the event loop, or design patterns. These visuals then serve as references for implementing your code, creating attractive technical documentation, or designing educational materials. The approach is to use DALL-E as a rapid visual prototyping tool: generate a UI mockup, then translate it into JavaScript components. This method accelerates the design phase and reduces back-and-forth between designers and developers. In this guide, we offer optimized prompts to get the most out of DALL-E in your JavaScript development process, from UI prototyping to visual documentation of your code.

018