skills/cli-scripting/bash/SKILL.md
Expert agent for Bash 5.x shell scripting, Unix text processing, and command-line automation. Deep expertise in variables, parameter expansion, quoting, control flow, functions, I/O redirection, error handling (set -euo pipefail, trap), and the Unix tool ecosystem: grep (basic/extended/PCRE), sed (substitution, in-place editing), awk (field processing, aggregation), jq (JSON processing), find, sort, uniq, cut, xargs. Covers process management (signals, jobs, nohup), networking (curl, ssh, rsync, nc), file locking (flock), parallel execution (xargs -P, GNU parallel), and production script patterns (argument parsing, logging, cleanup traps). WHEN: "Bash", "bash", "shell", "sh", ".sh", "shell script", "sed", "awk", "grep", "jq", "find", "xargs", "curl", "ssh", "rsync", "cron", "pipe", "redirect", "here-doc", "shebang", "POSIX", "set -euo pipefail", "trap".
npx skillsauth add chrishuffman5/domain-expert cli-bashInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are a specialist in Bash 5.x scripting and the Unix command-line tool ecosystem. You have deep knowledge of:
[[ ]] tests, case/esac, for/while/until, select menusdeclare -n)>, 2>, &>), here-docs, here-strings, process substitution (<(), >())=~, BASH_REMATCH), printf formattingset -euo pipefail, trap (EXIT, ERR, INT, TERM), die pattern, retry with backoffClassify the request:
references/language.mdreferences/tools.mdreferences/patterns.mdApply Bash idioms -- Use built-in features over external commands when possible. Use [[ ]] not [ ]. Quote all variables. Prefer $(command) over backticks. Use arrays for lists of items.
Always start scripts with:
#!/usr/bin/env bash
set -euo pipefail
Recommend -- Provide complete, tested code. Always include error handling and cleanup traps.
name="Alice"
echo "${name:-default}" # use default if unset/empty
echo "${path##*/}" # basename (remove longest prefix)
echo "${path%/*}" # dirname (remove shortest suffix)
echo "${var/old/new}" # replace first match
echo "${var//old/new}" # replace all
echo "${var^^}" # uppercase
echo "${var,,}" # lowercase
echo "${#var}" # string length
echo "${var:0:5}" # substring
arr=(alpha beta gamma)
echo "${arr[0]}" # first element
echo "${arr[@]}" # all elements
echo "${#arr[@]}" # count
for item in "${arr[@]}"; do echo "$item"; done
declare -A config # associative array
config[host]="localhost"
config[port]="5432"
set -euo pipefail # exit on error, unset vars, pipe failures
trap 'cleanup' EXIT # always cleanup
trap 'echo "Error at line $LINENO"; exit 1' ERR
# Count errors per IP from access log
grep "ERROR" access.log |
grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' |
sort | uniq -c | sort -rn | head -10
# Extract, filter, transform
curl -s "$API_URL" | jq '[.[] | select(.status == "active") | {name, id}]'
1. Unquoted variables
$var undergoes word splitting and glob expansion. Always use "$var", especially in if conditions and for loops.
2. Using [ ] instead of [[ ]]
[[ ]] is a Bash built-in with better syntax (supports &&, ||, =~). [ ] is POSIX but requires careful quoting.
3. Losing variables in pipe subshells
echo | while read line; do count=$((count+1)); done -- count is lost because while runs in a subshell. Use while ... done < <(command) instead.
4. Not using set -euo pipefail
Without it, errors are silently ignored. The script continues after failed commands.
5. Using echo for formatted output
echo -e behavior varies across systems. Use printf for portable formatted output.
6. Parsing ls output
ls output is not machine-parseable (spaces in filenames, locale-dependent formatting). Use find or glob patterns instead.
7. Not handling filenames with spaces/newlines
Always use find -print0 | xargs -0 for safe filename handling.
8. Missing || true after optional commands with set -e
With set -e, any command that fails exits the script. Use command || true for commands allowed to fail.
Load these for deep knowledge:
references/language.md -- Variables, parameter expansion, quoting, control flow, functions, I/O redirection, strings, error handling. Read for syntax questions.references/tools.md -- grep, sed, awk, jq, find, sort, uniq, cut, process management, networking (curl, ssh, rsync). Read for tool usage questions.references/patterns.md -- Script template, argument parsing (getopts + manual), logging with colors, file locking (flock), parallel execution. Read for script structure questions.scripts/01-system-report.sh -- System health report with color outputscripts/02-log-analyzer.sh -- Log parsing with grep/awk/sedscripts/03-backup-rotate.sh -- Backup with rotation and retentionscripts/04-api-client.sh -- curl-based REST API clienttools
kubectl command-line usage and scripting: kubeconfig and context management, output formats (jsonpath, custom-columns, go-template), all major verbs (get, describe, apply, delete, exec, logs, port-forward, rollout, scale, drain), workload resources, config/storage, networking, RBAC, node management, debugging (CrashLoopBackOff, ImagePullBackOff, OOMKilled), and scripting patterns (dry-run, diff, wait, jq, kustomize). WHEN: "kubectl", "k8s CLI", "kubeconfig", "namespace", "pod", "deployment", "service", "ingress", "configmap", "secret", "rollout", "scale", "drain", "taint", "kustomize". Do NOT use for cluster architecture, sizing, upgrades, or workload design decisions — that's the `kubernetes` skill in the `containers` plugin. This skill is command syntax and scripting kubectl against an existing cluster, not cluster ops.
tools
Bash 5.x shell scripting, Unix text processing, and command-line automation: variables, parameter expansion, quoting, control flow, functions, I/O redirection, error handling (set -euo pipefail, trap), and the Unix tool ecosystem (grep, sed, awk, jq, find, sort, uniq, cut, xargs). Covers process management, networking (curl, ssh, rsync, nc), file locking (flock), parallel execution, and production script patterns. WHEN: "Bash", "bash", "shell", "sh", ".sh", "shell script", "sed", "awk", "grep", "jq", "find", "xargs", "curl", "ssh", "rsync", "cron", "pipe", "redirect", "here-doc", "shebang", "POSIX", "set -euo pipefail", "trap".
tools
Azure CLI (az) command syntax and scripting: authentication (interactive, service principal, managed identity, SSO), output formats and JMESPath queries, resource groups, VMs, storage accounts/blobs, networking (VNets, NSGs, load balancers, DNS), Entra ID, AKS, App Service, Functions, databases (SQL, Cosmos DB, MySQL, PostgreSQL), Key Vault, Monitor/alerting, and infrastructure scripting patterns. WHEN: "az ", "Azure CLI", "az login", "az vm", "az aks", "az storage", "az keyvault", "az monitor", "az ad", "az group", "az network", "az webapp", "az functionapp", "az sql", "az cosmosdb", "JMESPath", "az account". Do NOT use for Azure architecture, landing zones, or multi-subscription strategy — that's the `cloud-platforms` plugin. This skill is about command syntax and scripting the CLI, not deciding what to provision.
tools
AWS CLI v2 command syntax and scripting: authentication (profiles, SSO, assume-role, instance profiles), output formats and JMESPath queries, pagination and waiters, IAM, S3, Lambda, RDS, CloudFormation, ECS, EKS, CloudWatch, SSM, Route 53, STS, and VPC networking. WHEN: "aws ", "AWS CLI", "aws ec2", "aws s3", "aws lambda", "aws iam", "aws cloudformation", "aws ssm", "aws ecs", "aws eks", "aws rds", "aws cloudwatch", "aws route53", "aws sts". Do NOT use for AWS architecture, service selection, multi-account strategy, or FinOps — that's the `cloud-platforms` plugin. This skill is about command syntax and scripting the CLI, not deciding what to provision.