A

Advanced Bash Platform

Enterprise-grade skill for bash, linux, terminal, patterns. Includes structured workflows, validation checks, and reusable patterns for development.

SkillClipticsdevelopmentv1.0.0MIT
0 views0 copies

Advanced Bash Platform

A Claude Code skill for writing robust, maintainable Bash scripts and shell automation. Covers scripting best practices, error handling, argument parsing, portability, performance optimization, and common patterns for system administration, CI/CD, and developer tooling.

When to Use This Skill

Choose Advanced Bash Platform when:

  • You need to write production-quality Bash scripts
  • You want robust error handling and debugging in shell scripts
  • You need to automate system administration tasks
  • You're building CI/CD pipeline scripts
  • You want to create developer tooling and CLI utilities with Bash

Consider alternatives when:

  • You need a full CLI application (use Node.js/Python with a CLI framework)
  • You want cross-platform scripting (use Python or Node.js)
  • You need complex data processing (use a programming language, not Bash)

Quick Start

# Install the skill claude install advanced-bash-platform # Write a robust script claude "Write a Bash script that deploys a Docker container with health checks, rollback on failure, and logging" # Add argument parsing claude "Add proper argument parsing to this script with --help, required and optional flags, and validation" # Debug a script claude "This script fails intermittently: [paste]. Add proper error handling and debugging output"

Core Concepts

Script Header Template

#!/usr/bin/env bash set -euo pipefail IFS=$'\n\t' # Script description # Usage: script.sh [options] <argument> readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"

Error Handling

SettingEffectWhen to Use
set -eExit on any errorAlways
set -uError on undefined variablesAlways
set -o pipefailCatch pipe failuresAlways
trap cleanup EXITRun cleanup on exitScripts with temp files
`true`

Common Patterns

PatternUse CaseImplementation
Argument ParsingCLI optionsgetopts or manual while case
LoggingStructured outputFunctions with timestamp and level
Temp FilesIntermediate datamktemp with trap cleanup
Lock FilesPrevent concurrent runsflock or PID file
ProgressLong operationsCounter with \r overwrite
RetryUnreliable commandsLoop with backoff

Configuration

ParameterTypeDefaultDescription
shellstring"bash"Target: bash, zsh, sh (POSIX)
stylestring"strict"Style: strict (set -euo), relaxed
loggingbooleantrueInclude logging functions
portabilitystring"bash"Portability: posix, bash, linux_only
complexitystring"moderate"Level: simple, moderate, advanced

Best Practices

  1. Always use set -euo pipefail — This catches the vast majority of scripting bugs: unhandled errors, undefined variables, and swallowed pipe failures. Every production Bash script should start with this.

  2. Quote all variable expansions"$variable" not $variable. Unquoted variables are split on whitespace and subject to glob expansion. This causes subtle bugs with filenames containing spaces or special characters.

  3. Use functions for organization — Any script longer than 50 lines should be organized into functions. Functions make scripts testable, reusable, and easier to read. Put the main logic in a main() function and call it at the bottom.

  4. Don't parse ls outputls output is not reliable for scripting. Use glob patterns for file iteration: for file in *.txt; do. Use find with -print0 and xargs -0 for complex file operations.

  5. Use shellcheck — Run ShellCheck on every Bash script. It catches hundreds of common scripting mistakes including quoting issues, undefined variables, and portability problems. Add it to your CI pipeline.

Common Issues

Script works locally but fails in CI — Different shell versions, missing utilities, or different PATH configurations. Use #!/usr/bin/env bash for portability, check for required tools at the start, and avoid bashisms if targeting sh.

Variable is empty when it shouldn't be — You're likely running in a subshell (pipe or command substitution) where the variable is set but not visible to the parent. Avoid setting variables inside while read loops with pipes — use process substitution instead.

Script is too slow — Avoid calling external commands in loops. Each grep, sed, or awk invocation forks a process. Use Bash built-ins for simple string operations and batch external tool usage where possible.

Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates