Skip to main content
Cloud & AI Hub
Browse
Glossary AI Directory Playgrounds Models Prompts Explainers Strategy Matrix Benchmark Decoder

Bash Shell Script Builder

Use Case: Automating server setup commands

Last reviewed: July 25, 2026

System Instructions

You are a systems administrator. Write a robust, POSIX-compliant Bash shell script to automate the specified server setup actions, including error handling.

User Prompt Template

Generate a Bash shell script to automate:

{SETUP_REQUIREMENTS}

Environment: {ENVIRONMENT_OS}

Run This Prompt — SDK Snippets

Implementation Guidelines

What This Prompt Does

This prompt converts high-level server configuration instructions or application installation requirements into a production-ready, POSIX-compliant Bash shell script. It enforces best practices such as strict error tracking (set -euo pipefail), root privilege verification, log validation, cleanup traps, and idempotent execution loops.

System Prompt

You are a senior Systems Engineer and Linux Systems Administrator.
Write a robust, POSIX-compliant Bash shell script to automate the specified setup actions.
Ensure the script adheres to these engineering standards:
1. Include 'set -euo pipefail' at the beginning to catch silent errors early.
2. Verify if the execution context has root/sudo privileges before running updates.
3. Use idempotency: check if packages, directories, and users already exist before attempting creation.
4. Output descriptive status messages using log colors (e.g. green for success, yellow for info, red for error).
5. Clean up temporary directories or files on exit using a trap handler.
6. Provide clear, in-line documentation explaining what each section does.

User Prompt Template

Generate a robust Bash shell script to automate the following setup actions:
{SETUP_REQUIREMENTS}

Target operating system: {ENVIRONMENT_OS}
(e.g., "Ubuntu 22.04 LTS", "Rocky Linux 9", "Debian 12")

Dependencies or pre-requisites: {DEPENDENCIES}

Include error handling and verification checks for each stage.

Example Output

#!/bin/bash
set -euo pipefail

# Log coloring helpers
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_err() { echo -e "${RED}[ERROR]${NC} $1"; }

# Verify root permissions
if [ "$EUID" -ne 0 ]; then
  log_err "Please run as root or with sudo."
  exit 1
fi

log_info "Setup completed successfully."

When to Use This

This prompt is a good fit for automating recurring operational tasks — log rotation, backup scripts, deployment helpers — where you know roughly what needs to happen but don’t want to hand-write bash’s occasionally fiddly syntax for error handling, argument parsing, or string manipulation from scratch every time.

Tips for Best Results

  • Explicitly ask for set -euo pipefail and proper error handling in generated scripts, since bash’s default behavior of silently continuing after a failed command is a common source of scripts that fail partway through without clearly signaling what went wrong.
  • Specify the target shell environment (bash version, whether it needs to be POSIX-compliant for portability, what utilities can be assumed available) since scripts relying on bash-specific features will fail unexpectedly on systems using a different default shell like dash.
  • Review any generated script that handles file deletion, permission changes, or system configuration line by line before running it, particularly with elevated privileges — the cost of a bad automated script running with sudo can be considerably higher than the time saved by skipping review.