
bash-pro
Master of defensive Bash scripting for production automation, CI/CD pipelines, and system utilities. Expert in safe, portable, and testable shell scripts.
- Installs
- 967
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/sickn33/agentic-awesome-skills --skill bash-pro- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads bash-pro automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Use this skill when
- Writing or reviewing Bash scripts for automation, CI/CD, or ops
- Hardening shell scripts for safety and portability
Do not use this skill when
- You need POSIX-only shell without Bash features
- The task requires a higher-level language for complex logic
- You need Windows-native scripting (PowerShell)
Instructions
- Define script inputs, outputs, and failure modes.
- Apply strict mode and safe argument parsing.
- Implement core logic with defensive patterns.
- Add tests and linting with Bats and ShellCheck.
Safety
- Treat input as untrusted; avoid eval and unsafe globbing.
- Prefer dry-run modes before destructive actions.
Focus Areas
- Defensive programming with strict error handling
- POSIX compliance and cross-platform portability
- Safe argument parsing and input validation
- Robust file operations and temporary resource management
- Process orchestration and pipeline safety
- Production-grade logging and error reporting
- Comprehensive testing with Bats framework
- Static analysis with ShellCheck and formatting with shfmt
- Modern Bash 5.x features and best practices
- CI/CD integration and automation workflows
Approach
- Always use strict mode with
set -Eeuo pipefailand proper error trapping - Quote all variable expansions to prevent word splitting and globbing issues
- Prefer arrays and proper iteration over unsafe patterns like
for f in $(ls) - Use
[[ ]]for Bash conditionals, fall back to[ ]for POSIX compliance - Implement comprehensive argument parsing with
getoptsand usage functions - Create temporary files and directories safely with
mktempand cleanup traps - Prefer
printfoverechofor predictable output formatting - Use command substitution
$()instead of backticks for readability - Implement structured logging with timestamps and configurable verbosity
- Design scripts to be idempotent and support dry-run modes
- Use
shopt -s inherit_errexitfor better error propagation in Bash 4.4+ - Employ
IFS=$'\n\t'to prevent unwanted word splitting on spaces - Validate inputs with
: "${VAR:?message}"for required environment variables - End option parsing with
--and userm -rf -- "$dir"for safe operations - Allow
set -xonly on redacted non-secret paths; tracing expands credentials and arguments - Use
xargs -0with NUL boundaries for safe subprocess orchestration - Employ
readarray/mapfilefor safe array population from command output - Implement robust script directory detection:
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" - Use NUL-safe patterns:
find -print0 | while IFS= read -r -d '' file; do ...; done
Compatibility & Portability
- Use
#!/usr/bin/env bashshebang for portability across systems - Check Bash version at script start:
(( BASH_VERSINFO[0] > 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 4) ))for Bash 4.4+ features - Validate required external commands exist:
command -v jq &>/dev/null || exit 1 - Detect platform differences:
case "$(uname -s)" in Linux*) ... ;; Darwin*) ... ;; esac - Handle GNU vs BSD tool differences (e.g.,
sed -ivssed -i '') - Test scripts on all target platforms (Linux, macOS, BSD variants)
- Document minimum version requirements in script header comments
- Provide fallback implementations for platform-specific features
- Use built-in Bash features over external commands when possible for portability
- Avoid bashisms when POSIX compliance is required, document when using Bash-specific features
Readability & Maintainability
- Use long-form options in scripts for clarity:
--verboseinstead of-v - Employ consistent naming: snake_case for functions/variables, UPPER_CASE for constants
- Add section headers with comment blocks to organize related functions
- Keep functions under 50 lines; refactor larger functions into smaller components
- Group related functions together with descriptive section headers
- Use descriptive function names that explain purpose:
validate_input_filenotcheck_file - Add inline comments for non-obvious logic, avoid stating the obvious
- Maintain consistent indentation (2 or 4 spaces, never tabs mixed with spaces)
- Place opening braces on same line for consistency:
function_name() { - Use blank lines to separate logical blocks within functions
- Document function parameters and return values in header comments
- Extract magic numbers and strings to named constants at top of script
Safety & Security Patterns
- Declare constants with
readonlyto prevent accidental modification - Use
localkeyword for all function variables to avoid polluting global scope - Implement
timeoutfor external commands:curl --connect-timeout 5 --max-time 30 ...bounds a network call; GNU timeout is not bundled on macOS - Validate file permissions before operations:
[[ -r "$file" ]] || exit 1 - Process substitution can hide producer failure from pipefail; explicitly wait/check it for critical inputs
- Sanitize user input before using in commands or file operations
- Validate numeric input with pattern matching:
[[ $num =~ ^[0-9]+$ ]] - Never use
evalon user input; use arrays for dynamic command construction - Set restrictive umask for sensitive operations:
(umask 077; touch "$secure_file") - Log security-relevant operations (authentication, privilege changes, file access)
- Use
--to separate options from arguments:rm -rf -- "$user_input" - Validate environment variables before using:
: "${REQUIRED_VAR:?not set}" - Check exit codes of all security-critical operations explicitly
- Use
trapto ensure cleanup happens even on abnormal exit
Performance Optimization
- Avoid subshells in loops; use
while readinstead offor i in $(cat file) - Use Bash built-ins over external commands:
[[ ]]instead oftest,${var//pattern/replacement}instead ofsed - Batch operations instead of repeated single operations (e.g., one
sedwith multiple expressions) - Use
mapfile/readarrayfor efficient array population from command output - Avoid repeated command substitutions; store result in variable once
- Use arithmetic expansion
$(( ))instead ofexprfor calculations - Prefer
printfoverechofor formatted output (faster and more reliable) - Use associative arrays for lookups instead of repeated grepping
- Process files line-by-line for large files instead of loading entire file into memory
- Use
xargs -Pfor parallel processing when operations are independent
Documentation Standards
- Implement
--helpand-hflags showing usage, options, and examples - Provide
--versionflag displaying script version and copyright information - Include usage examples in help output for common use cases
- Document all command-line options with descriptions of their purpose
- List required vs optional arguments clearly in usage message
- Document exit codes: 0 for success, 1 for general errors, specific codes for specific failures
- Include prerequisites section listing required commands and versions
- Add header comment block with script purpose, author, and modification date
- Document environment variables the script uses or requires
- Provide troubleshooting section in help for common issues
- Generate documentation with
shdocfrom special comment formats - Create man pages using
shellmanfor system integration - Include architecture diagrams using Mermaid or GraphViz for complex scripts
Modern Bash Features (5.x)
- Verify each needed feature against the target Bash manual instead of assuming all Bash 5.x versions share transformations, shopt options and redirection behavior.
EPOCHREALTIMEreports epoch seconds with microsecond granularity; it is a wall clock, not a monotonic benchmark timer.- Check version before using modern features:
(( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 2) )) - Use
${parameter@Q}for shell-quoted output (Bash 4.4+) - Use
${parameter@E}for escape sequence expansion (Bash 4.4+) - Use
${parameter@P}for prompt expansion (Bash 4.4+) - Use
${parameter@A}for assignment format (Bash 4.4+) - Employ
wait -nto wait for any background job (Bash 4.3+) - Use
mapfile -d delimfor custom delimiters (Bash 4.4+)
CI/CD Integration
- GitHub Actions: Use
shellcheck-problem-matchersfor inline annotations - Pre-commit hooks: Configure
.pre-commit-config.yamlwithshellcheck,shfmt,checkbashisms - Matrix testing: Test across Bash 4.4, 5.0, 5.1, 5.2 on Linux and macOS
- Container testing: Use official bash:5.2 Docker images for reproducible tests
- CodeQL: Use supported-language analysis where applicable; it is not a general Bash analyzer
- Actionlint: Validate GitHub Actions workflow files that use shell scripts
- Automated releases: Tag versions and generate changelogs automatically
- Coverage reporting: Track test coverage and fail on regressions
- Example workflow:
shellcheck *.sh && shfmt -d *.sh && bats test/
Security Scanning & Hardening
- SAST: Integrate Semgrep with custom rules for shell-specific vulnerabilities
- Secrets detection: Use
gitleaksortrufflehogto prevent credential leaks - Supply chain: Verify checksums of sourced external scripts
- Sandboxing: Inspect untrusted scripts as data first; a container alone does not authorize execution or isolate network/mounts/secrets
- SBOM: Document dependencies and external tools for compliance
- Security linting: Use ShellCheck with security-focused rules enabled
- Privilege analysis: Audit scripts for unnecessary root/sudo requirements
- Input sanitization: Validate all external inputs against allowlists
- Audit logging: Log all security-relevant operations to syslog
- Container security: Scan script execution environments for vulnerabilities
Observability & Logging
- Structured logging: Output JSON for log aggregation systems
- Log levels: Implement DEBUG, INFO, WARN, ERROR with configurable verbosity
- Syslog integration: Use
loggercommand for system log integration - Distributed tracing: Add trace IDs for multi-script workflow correlation
- Metrics export: Output Prometheus-format metrics for monitoring
- Error context: Include redacted locations/status; never dump environment variables or expanded secret commands
- Log rotation: Configure log file rotation for long-running scripts
- Performance metrics: Track execution time, resource usage, external call latency
- Example:
log_info() { logger -t "$SCRIPT_NAME" -p user.info "$*"; echo "[INFO] $*" >&2; }
Quality Checklist
- Scripts pass ShellCheck static analysis with minimal suppressions
- Code is formatted consistently with shfmt using standard options
- Comprehensive test coverage with Bats including edge cases
- All variable expansions are properly quoted
- Error handling covers all failure modes with meaningful messages
- Temporary resources are cleaned up properly with EXIT traps
- Scripts support
--helpand provide clear usage information - Input validation prevents injection attacks and handles edge cases
- Scripts are portable across target platforms (Linux, macOS)
- Performance is adequate for expected workloads and data sizes
Output
- Production-ready Bash scripts with defensive programming practices
- Comprehensive test suites using bats-core or shellspec with TAP output
- CI/CD pipeline configurations (GitHub Actions, GitLab CI) for automated testing
- Documentation generated with shdoc and man pages with shellman
- Structured project layout with reusable library functions and dependency management
- Static analysis configuration files (.shellcheckrc, .shfmt.toml, .editorconfig)
- Performance benchmarks and profiling reports for critical workflows
- Security review with SAST, secrets scanning, and vulnerability reports
- Debugging utilities with trace modes, structured logging, and observability
- Migration guides for Bash 3→5 upgrades and legacy modernization
- Package distribution configurations (Homebrew formulas, deb/rpm specs)
- Container images for reproducible execution environments
Essential Tools
Static Analysis & Formatting
- ShellCheck: Static analyzer with
enable=allandexternal-sources=trueconfiguration - shfmt: Shell script formatter with standard config (
-i 2 -ci -bn -sr -kp) - checkbashisms: Detect bash-specific constructs for portability analysis
- Semgrep: SAST with custom rules for shell-specific security issues
- CodeQL: Supported-language/Actions analysis; use ShellCheck for standalone Bash
Testing Frameworks
- bats-core: Maintained fork of Bats with modern features and active development
- shellspec: BDD-style testing framework with rich assertions and mocking
- shunit2: xUnit-style testing framework for shell scripts
- bashing: Testing framework with mocking support and test isolation
Modern Development Tools
- bashly: CLI framework generator for building command-line applications
- basher: Bash package manager for dependency management
- bpkg: Alternative bash package manager with npm-like interface
- shdoc: Generate markdown documentation from shell script comments
- shellman: Generate man pages from shell scripts
CI/CD & Automation
- pre-commit: Multi-language pre-commit hook framework
- actionlint: GitHub Actions workflow linter
- gitleaks: Secrets scanning to prevent credential leaks
- Makefile: Automation for lint, format, test, and release workflows
Common Pitfalls to Avoid
for f in $(ls ...)causing word splitting/globbing bugs (usefind -print0 | while IFS= read -r -d '' f; do ...; done)- Unquoted variable expansions leading to unexpected behavior
- Relying on
set -ewithout proper error trapping in complex flows - Using
echofor data output (preferprintffor reliability) - Missing cleanup traps for temporary files and directories
- Unsafe array population (use
readarray/mapfileinstead of command substitution) - Ignoring binary-safe file handling (always consider NUL separators for filenames)
Dependency Management
- Package managers: Use
basherorbpkgfor installing shell script dependencies - Vendoring: Copy dependencies into project for reproducible builds
- Lock files: Document exact versions of dependencies used
- Checksum verification: Verify integrity of sourced external scripts
- Version pinning: Lock dependencies to specific versions to prevent breaking changes
- Dependency isolation: Use separate directories for different dependency sets
- Update automation: Automate dependency updates with Dependabot or Renovate
- Security scanning: Scan dependencies for known vulnerabilities
- Example:
basher install username/repo@versionorbpkg install username/repo -g
Advanced Techniques
- Error Context: Use
trap 'echo "Error at line $LINENO: exit $?" >&2' ERRfor debugging - Safe Temp Handling:
tmpdir=$(mktemp -d) || exit 1; trap 'rm -rf -- "$tmpdir"' EXIT - Version Checking:
(( BASH_VERSINFO[0] >= 5 ))before using modern features - Binary-Safe Arrays:
readarray -d '' files < <(find . -print0) - Function Returns: Use
declare -g resultfor returning complex data from functions - Associative Arrays:
declare -A config=([host]="localhost" [port]="8080")for complex data structures - Parameter Expansion:
${filename%.sh}remove extension,${path##*/}basename,${text//old/new}replace all - Signal Handling:
trap cleanup_function SIGHUP SIGINT SIGTERMfor graceful shutdown - Command Grouping:
{ cmd1; cmd2; } > output.logshare redirection,( cd dir && cmd )use subshell for isolation - Co-processes:
coproc proc { cmd; }; echo "data" >&"${proc[1]}"; read -u "${proc[0]}" resultfor bidirectional pipes - Here-documents:
cat <<-'EOF'with-strips leading tabs, quotes prevent expansion - Process Management:
wait $pidto wait for background job,jobs -plist background PIDs - Conditional Execution:
cmd1 && cmd2run cmd2 only if cmd1 succeeds,cmd1 || cmd2run cmd2 if cmd1 fails - Brace Expansion:
touch file{1..10}.txtcreates multiple files efficiently - Nameref Variables:
declare -n ref=varnamecreates reference to another variable (Bash 4.3+) - Improved Error Trapping:
set -Eeuo pipefail; shopt -s inherit_errexitfor comprehensive error handling - Parallel Execution:
xargs -P $(nproc) -n 1 commandfor parallel processing with CPU core count - Structured Output:
jq -n --arg key "$value" '{key: $key}'for JSON generation - Performance Profiling: Use
time -vfor detailed resource usage orTIMEFORMATfor custom timing
References & Further Reading
Style Guides & Best Practices
- Google Shell Style Guide - Comprehensive style guide covering quoting, arrays, and when to use shell
- Bash Pitfalls - Catalog of common Bash mistakes and how to avoid them
- Bash Hackers Wiki - Comprehensive Bash documentation and advanced techniques
- Defensive BASH Programming - Modern defensive programming patterns
Tools & Frameworks
- ShellCheck - Static analysis tool and extensive wiki documentation
- shfmt - Shell script formatter with detailed flag documentation
- bats-core - Maintained Bash testing framework
- shellspec - BDD-style testing framework for shell scripts
- bashly - Modern Bash CLI framework generator
- shdoc - Documentation generator for shell scripts
Security & Advanced Topics
- Bash Security Best Practices - Security-focused shell script patterns
- Awesome Bash - Curated list of Bash resources and tools
- Pure Bash Bible - Collection of pure bash alternatives to external commands
Example
#!/usr/bin/env bash
set -Eeuo pipefail
umask 077
task_tmpdir=$(mktemp -d) || exit 1
trap 'rm -rf -- "$task_tmpdir"' EXIT
printf '%s\n' 'example' > "$task_tmpdir/input.txt"
[[ -s "$task_tmpdir/input.txt" ]] || exit 1
The directory is created before installing cleanup. Quote/validate approved paths
before deletion: -- stops option parsing but does not prevent deleting a wrong
absolute path. Strict mode and an ERR trap do not catch every failure context.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Primary language support: CodeQL supported languages.
FAQ
What does the bash-pro skill do?
Master of defensive Bash scripting for production automation, CI/CD pipelines, and system utilities. Expert in safe, portable, and testable shell scripts.
How do I install bash-pro?
Run npx skills add https://github.com/sickn33/agentic-awesome-skills --skill bash-pro in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/bash-pro/ (personal) or .claude/skills/bash-pro/ (project).
Which AI agents can use bash-pro?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is bash-pro safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains bash-pro?
It is published by sickn33 in sickn33/agentic-awesome-skills. It has 967 recorded installs.
More from sickn33/agentic-awesome-skills
docker-expert
sickn33/agentic-awesome-skills
You are an advanced Docker containerization expert with comprehensive, practical knowledge of container optimization, security hardening, multi-stage builds, orchestration patterns, and production deployment strategies based on current industry best practices.
nodejs-best-practices
sickn33/agentic-awesome-skills
Node.js development principles and decision-making. Framework selection, async patterns, security, and architecture. Teaches thinking, not copying.
typescript-expert
sickn33/agentic-awesome-skills
TypeScript and JavaScript expert with deep knowledge of type-level programming, performance optimization, monorepo management, migration strategies, and modern tooling.
clean-code
sickn33/agentic-awesome-skills
This skill embodies the principles of "Clean Code" by Robert C. Martin (Uncle Bob). Use it to transform "code that works" into "code that is clean."
api-security-best-practices
sickn33/agentic-awesome-skills
Implement secure API design patterns including authentication, authorization, input validation, rate limiting, and protection against common API vulnerabilities
nextjs-best-practices
sickn33/agentic-awesome-skills
Next.js App Router principles. Server Components, data fetching, routing patterns.
Popular devops & cloud skills
microsoft-foundry
microsoft/azure-skills
Build, deploy, evaluate, optimize, fine-tune, and manage Microsoft Foundry agents, models, and resources end to end. USE FOR: foundry, azd ai agent, azd provision/deploy, hosted agent scaffold/develop/run/deploy/troubleshoot, prompt agent create, managed harness agent create, GitHub Copilot harness agent, create agent, update agent, add tool to agent, invoke agent, agent insights, evaluate agent, batch eval, continuous eval, continuous monitoring, agent CI/CD, optimize prompt, improve prompt, optimize agent instructions, Agent Optimizer scaffold, dataset curation from traces, deploy model, model fine-tuning (SFT/DPO/RFT), Foundry project, RBAC, role assignment, permissions, quota, capacity, region, deployment failure, AI Services, create Foundry resource, knowledge index, customize deployment, onboard, availability, training-data, grader, distillation, large file upload. DO NOT USE FOR: Azure Functions, App Service, general Azure deploy (use azure-deploy), general Azure prep (use azure
azure-diagnostics
microsoft/azure-skills
Debug Azure production issues on Azure using AppLens, Azure Monitor, resource health, and safe triage. WHEN: debug production issues, troubleshoot app service, app service high CPU, app service deployment failure, troubleshoot container apps, container app 503 or target port mismatch, troubleshoot functions, function telemetry missing or stopped after a config/connection-string change, troubleshoot AKS, VM RDP, Linux SSH, VM black screen, can't connect to VM, reset VM password, NSG or firewall blocking, kubectl cannot connect, kube-system/CoreDNS failures, pod pending, crashloop, node not ready, upgrade failures, analyze logs, KQL, insights, image pull failures, cold start issues, health probe failures, resource health, root cause of errors, troubleshoot event hubs, troubleshoot service bus, messaging SDK error, AMQP connection failure, message lock lost, lock renewal during long-running processing, service bus dead letter.
azure-prepare
microsoft/azure-skills
Prepare azd-based Azure projects for deployment: generates azure.yaml, infrastructure (Bicep/Terraform), and Dockerfiles for the Azure Developer CLI (azd) workflow. USE ONLY when the user explicitly wants to use azd as the deployment tool, or the project already has an azure.yaml file. DO NOT USE FOR: non-azd deployments, Python App Service code-only deploys (use python-appservice-deploy), or cross-cloud migration (use azure-cloud-migrate). WHEN: prepare app for azd, create azure.yaml, set up azd infrastructure, modernize app for Azure with azd, deploy with azd, function app, timer trigger, service bus trigger, event-driven function, managed identity, generate Bicep, generate Terraform, create and deploy to Azure.
azure-ai
microsoft/azure-skills
Use for Azure AI: Search, Speech, OpenAI, Document Intelligence. Helps with search, vector/hybrid search, speech-to-text, text-to-speech, transcription, OCR. WHEN: AI Search, query search, vector search, hybrid search, semantic search, speech-to-text, text-to-speech, transcribe, OCR, convert text to speech.
azure-deploy
microsoft/azure-skills
Execute Azure deployments for ALREADY-PREPARED applications that have existing .azure/deployment-plan.md and infrastructure files. DO NOT use this skill when the user asks to CREATE a new application — use azure-prepare instead. This skill runs azd up, azd deploy, terraform apply, and az deployment commands with built-in error recovery. Requires .azure/deployment-plan.md from azure-prepare and validated status from azure-validate. WHEN: "run azd up", "run azd deploy", "execute deployment", "push to production", "push to cloud", "go live", "ship it", "bicep deploy", "terraform apply", "publish to Azure", "launch on Azure". DO NOT USE WHEN: "create and deploy", "build and deploy", "create a new app", "set up infrastructure", "create and deploy to Azure using Terraform" — use azure-prepare for these.
azure-validate
microsoft/azure-skills
Pre-deployment validation for Azure readiness. Run deep checks on configuration, infrastructure (Bicep or Terraform), RBAC role assignments, managed identity permissions, and prerequisites before deploying. WHEN: validate my app, check deployment readiness, run preflight checks, verify configuration, check if ready to deploy, validate azure.yaml, validate Bicep, test before deploying, troubleshoot deployment errors, validate Azure Functions, validate function app, validate serverless deployment, verify RBAC roles, check role assignments, review managed identity permissions, what-if analysis, validate Container Apps deployment.