Skip to content
Back to skills

Bash

ASecurity

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\"...

  • 4 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 24, 2026
toolsgoshellbashapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 8 files and shows the line behind each finding

Scanned September 24, 2026

npx -y skills add chrishuffman5/domain-expert --skill bash --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Bash?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Bash
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/chrishuffman5-bash/badge)](https://www.skillsdirectory.com/skills/chrishuffman5-bash)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: bash
description: "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\"."
license: MIT
---

# Bash Technology Expert

This skill covers Bash 5.x scripting and the Unix command-line tool ecosystem. Read it for:

- Variables: quoting rules, parameter expansion, arithmetic, arrays (indexed + associative)
- Control flow: `[[ ]]` tests, case/esac, for/while/until, select menus
- Functions: local scope, return codes, output capture, namerefs (`declare -n`)
- I/O: file descriptors, redirection (`>`, `2>`, `&>`), here-docs, here-strings, process substitution (`<()`, `>()`)
- Strings: substring extraction, case conversion, regex matching (`=~`, `BASH_REMATCH`), printf formatting
- Error handling: `set -euo pipefail`, trap (EXIT, ERR, INT, TERM), die pattern, retry with backoff
- Text processing: grep (basic/extended/PCRE), sed (substitution, ranges, in-place), awk (fields, arrays, aggregation), jq (JSON)
- File tools: find (by name/size/time/permissions, -exec), sort, uniq, cut, paste, comm, diff, head, tail
- Process management: ps, jobs, signals (kill, trap), nohup, disown, timeout, wait
- Networking: curl (REST, auth, retry, timing), ssh (tunnels, config, jump hosts), scp, rsync, nc
- Script patterns: argument parsing (getopts, manual), logging with colors, file locking (flock), parallel execution (xargs -P, GNU parallel)

## How to Approach Tasks

1. **Classify** the request:
   - **Language/syntax** -- Load `references/language.md`
   - **Tools** -- Load `references/tools.md`
   - **Script patterns** -- Load `references/patterns.md`

2. **Apply 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.

3. **Always start scripts with:**
   ```bash
   #!/usr/bin/env bash
   set -euo pipefail
   ```

4. **Recommend** -- Provide complete, tested code. Always include error handling and cleanup traps.

## Core Expertise Overview

### Variables and Parameter Expansion

```bash
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
```

### Arrays

```bash
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"
```

### Error Handling

```bash
set -euo pipefail              # exit on error, unset vars, pipe failures
trap 'cleanup' EXIT            # always cleanup
trap 'echo "Error at line $LINENO"; exit 1' ERR
```

### Text Processing Pipeline

```bash
# 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
```

### JSON Processing with jq

```bash
# Extract, filter, transform
curl -s "$API_URL" | jq '[.[] | select(.status == "active") | {name, id}]'
```

## Common Pitfalls

**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.

## Reference Files

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.

## Example Scripts

- `scripts/01-system-report.sh` -- System health report with color output
- `scripts/02-log-analyzer.sh` -- Log parsing with grep/awk/sed
- `scripts/03-backup-rotate.sh` -- Backup with rotation and retention
- `scripts/04-api-client.sh` -- curl-based REST API client

Files in this skill

  • SKILL.md5.9 KB
  • references/language.md7.1 KB
  • references/patterns.md6.9 KB
  • references/tools.md8.7 KB
  • scripts/01-system-report.sh4.6 KB
  • scripts/02-log-analyzer.sh4.1 KB
  • scripts/03-backup-rotate.sh5.5 KB
  • scripts/04-api-client.sh7.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…