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.zipInstalls 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.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
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
- Quote all variables:
"$var" - Use
[[instead of[ - Use
localin functions - Use
readonlyfor constants - Always use
set -euo pipefail - 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.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| bash (this skill) | 0 | 3mo | Review | Beginner |
| bash-linux | 7 | 6mo | Review | Intermediate |
| create-worktree-skill | 2 | 9mo | No flags | Intermediate |
| domain-dns-ops | 2 | 2mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
bash-linux
davila7
Bash/Linux terminal patterns. Critical commands, piping, error handling, scripting. Use when working on macOS or Linux systems.
create-worktree-skill
disler
Use when the user explicitly asks for a SKILL to create a worktree. If the user does not mention "skill" or explicitly request skill invocation, do NOT trigger this. Only use when user says things like "use a skill to create a worktree" or "invoke the worktree skill". Creates isolated git worktrees with parallel-running configuration.
domain-dns-ops
steipete
Domain/DNS ops across Cloudflare, DNSimple, Namecheap for Peter. Use for onboarding zones to Cloudflare, flipping nameservers, setting redirects (Page Rules/Rulesets/Workers), updating redirect-worker mappings, and verifying DNS/HTTP. Source of truth: ~/Projects/manager.
moai-workflow-worktree
modu-ai
Git worktree management for parallel SPEC development with isolated workspaces, automatic registration, and seamless MoAI-ADK integration
k8s-operations
rohitg00
kubectl operations for applying, patching, deleting, and executing commands on Kubernetes resources. Use when modifying resources, running commands in pods, or managing resource lifecycle.
makefile-dev-workflow
raphaelmansuy
Unified development workflow for EdgeQuake using Makefile commands. Use when starting services, running tests, or managing the full development stack (database, backend, frontend). Provides simplified alternatives to raw cargo/npm commands.