Best-practice templates and safety standards for Bash shell scripting.

Install

mkdir -p .claude/skills/bash-alexandrexgoulart && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/12394" && unzip -o skill.zip -d .claude/skills/bash-alexandrexgoulart && rm skill.zip

Installs to .claude/skills/bash-alexandrexgoulart

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Write Bash scripts following best practices. Use when creating shell scripts, automation, or CLI tools. Covers safe scripting patterns.
135 chars✓ has a “when” trigger
Beginner

Key capabilities

  • Define script descriptions and usage instructions
  • Set safety options like exiting on error or undefined variables
  • Declare and manipulate variables including default values and string operations
  • Perform conditional tests for files, directories, strings, and numbers
  • Implement functions for logging, error handling, and command validation
  • Handle errors with traps and conditional command execution

How it works

The skill provides a template and examples for structuring Bash scripts, defining variables, handling conditions, and implementing functions. It includes safety settings and error handling mechanisms to ensure script reliability.

Inputs & outputs

You give it
Bash script logic, variables, and commands
You get back
Executable Bash script following best practices

When to use bash

  • Writing automation scripts
  • Creating CLI tools
  • Standardizing shell script safety

About this skill

Bash Scripting

Script Template

#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

# Script description
# Usage: ./script.sh <arg1> <arg2>

readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

main() {
    local arg1="${1:-default}"

    # Script logic here
    echo "Running with: $arg1"
}

main "$@"

Safety Settings

set -e          # Exit on error
set -u          # Error on undefined variables
set -o pipefail # Catch pipe failures
set -x          # Debug: print commands

Variables

# Declaration
readonly CONST="immutable"
local var="function scoped"

# Default values
name="${1:-default}"      # Use default if unset
name="${1:?Error: missing}"  # Error if unset

# String operations
"${var^^}"    # Uppercase
"${var,,}"    # Lowercase
"${var#prefix}"  # Remove prefix
"${var%suffix}"  # Remove suffix

Conditionals

# File tests
[[ -f "$file" ]]  # Is file
[[ -d "$dir" ]]   # Is directory
[[ -r "$file" ]]  # Is readable
[[ -x "$file" ]]  # Is executable

# String tests
[[ -z "$var" ]]   # Is empty
[[ -n "$var" ]]   # Is not empty
[[ "$a" == "$b" ]] # Equals

# Numeric tests
(( num > 5 ))     # Greater than
(( num == 5 ))    # Equals

Functions

log() {
    local level="$1"
    local message="$2"
    echo "[$(date +'%Y-%m-%d %H:%M:%S')] [$level] $message" >&2
}

die() {
    log "ERROR" "$1"
    exit 1
}

require_command() {
    command -v "$1" >/dev/null 2>&1 || die "Required command not found: $1"
}

Error Handling

# Trap for cleanup
cleanup() {
    rm -rf "$TMP_DIR"
}
trap cleanup EXIT

# Catch errors
if ! result=$(some_command 2>&1); then
    die "Command failed: $result"
fi

Loops

# For loop
for item in "${array[@]}"; do
    echo "$item"
done

# While read
while IFS= read -r line; do
    echo "$line"
done < file.txt

# Process substitution
while read -r line; do
    echo "$line"
done < <(command)

Best Practices

  1. Quote all variables: "$var"
  2. Use [[ instead of [
  3. Use local in functions
  4. Use readonly for constants
  5. Always use set -euo pipefail
  6. Use shellcheck for linting

When not to use it

  • When not creating shell scripts
  • When not automating tasks
  • When not building CLI tools

Limitations

  • Limited to Bash scripting
  • Focuses on script structure and safety, not advanced algorithms

How it compares

This skill provides a structured template and explicit safety settings for Bash scripts, unlike writing scripts without predefined best practices.

Compared to similar skills

bash side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
bash (this skill)03moReviewBeginner
bash-linux76moReviewIntermediate
create-worktree-skill29moNo flagsIntermediate
domain-dns-ops22moReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry