Skip to content
Skills Library
Programming · Building & coding

bash-scripting-expert

/bash-scripting-expert

Expert Bash scripting: robust, safe, portable shell scripts. Trigger keywords: bash, shell script, sh, quoting, word splitting, set -euo pipefail, trap, IFS, getopts, mktemp, shellcheck, POSIX, CLI, automation. Use for writing/debugging shell scripts and automation, or fixing quoting, exit-code, and portability bugs.

Licence
MIT
Last repository change
31.05.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 31.05.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Expert Bash scripting: robust, safe, portable shell scripts. Trigger keywords: bash, shell script, sh, quoting, word splitting, set -euo pipefail, trap, IFS, getopts, mktemp, shellcheck, POSIX, CLI, automation. Use for writing/debugging shell scripts and automation, or fixing quoting, exit-code, and portability bugs.

Original author description

Expert Bash scripting: robust, safe, portable shell scripts. Trigger keywords: bash, shell script, sh, quoting, word splitting, set -euo pipefail, trap, IFS, getopts, mktemp, shellcheck, POSIX, CLI, automation. Use for writing/debugging shell scripts and automation, or fixing quoting, exit-code, and portability bugs.

How it works

  1. When to Use
  2. When NOT to Use
  3. Core Principles
  4. Common Mistakes
  5. Examples
  6. See Also
Original SKILL.md headings · 78 lines, 549 words
SKILL.md preview
---
name: bash-scripting-expert
description: "Expert Bash scripting: robust, safe, portable shell scripts. Trigger keywords: bash, shell script, sh, quoting, word splitting, set -euo pipefail, trap, IFS, getopts, mktemp, shellcheck, POSIX, CLI, automation. Use for writing/debugging shell scripts and automation, or fixing quoting, exit-code, and portability bugs."
---

# Bash Scripting Expert

> Scripts fail in production on the input you didn't quote. Start strict, quote everything, clean up on exit, and run ShellCheck. When logic gets complex (JSON, data structures), switch to a real language.

## When to Use
- Writing or debugging a Bash/POSIX shell script or CI/automation glue.
- "Works until a path has a space/newline" bugs; word-splitting, globbing, quoting.
- Argument parsing, exit codes, error handling, temp files, cleanup.

## When NOT to Use
- Complex data/JSON/HTTP logic → `python-expert` (shell is the wrong tool).
- PowerShell scripting → use PowerShell tooling.
- CI pipeline YAML → `github-master`.

## Core Principles

### 1. Strict mode, every script
- `#!/usr/bin/env bash` + `set -euo pipefail`: exit on error, error on unset vars, fail on any pipeline stage. Set `IFS=$'\n\t'` to stop surprise word-splitting on spaces.
- Know `set -e`'s gotchas: it's suppressed inside `if`/`||`/`&&` conditions and command substitutions — check critical commands explicitly when needed.

### 2. Quote everything
- Always `"$var"`, `"${arr[@]}"`, `"$@"` (not `$*`). Unquoted expansions split on `IFS` and glob — the #1 source of bugs.
- Use `[[ … ]]` for tests (not `[ … ]`), `$(…)` not backticks, `(( … ))` for arithmetic, and `local` for all function variables.

### 3. Errors, cleanup, and exit codes
- `trap 'cleanup' EXIT` to remove temp files even on failure/interrupt. Create temps with `mktemp`.
- Validate args and required commands up front; print usage to **stderr** and `exit` non-zero on misuse. Exit codes are meaningful — `0` success, non-zero failure.
- Send errors/logs to `stderr` (`>&2`); keep `stdout` for real output so the script composes in pipes.

### 4. Robust file & data handling
- `printf` over `echo` for anything with escapes/variables. Use `--` before paths, and `find … -print0 | while IFS= read -r -d ''` for filenames with spaces/newlines.
- For POSIX `sh`, avoid bashisms (`[[`, arrays, `local`); if you use them, declare `bash` in the shebang. Lint with **ShellCheck** and format with `shfmt`.

## Common Mistakes
- **Unquoted `$var`** → breaks on spaces/globs/empties.
- **Parsing `ls`** or `for f in $(ls)` → use globs or `find -print0`.
- **`set -e` assumed to catch everything** → it won't inside conditions/substitutions; check explicitly.
- **`cd somewhere` without `||exit`** → subsequent commands run in the wrong directory.
- **No cleanup trap** → leftover temp files on failure.
- **`echo` with `-e`/escapes** → non-portable; use `printf`.
- **Mixing logs into stdout** → corrupts piped output.

## Examples

**Defensive script skeleton**
```bash
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

usage() { printf 'usage: %s <input-dir> <out-file>\n' "$0" >&2; exit 2; }
[[ $# -eq 2 ]] || usage

input_dir=$1
out_file=$2
[[ -d $input_dir ]] || { printf 'no such dir: %s\n' "$input_dir" >&2; exit 1; }
command -v jq >/dev/null || { printf 'jq required\n' >&2; exit 1; }

tmp=$(mktemp)
trap 'rm -f "$tmp"' EXIT

# safe iteration (handles spaces/newlines in names)
find "$input_dir" -type f -name '*.log' -print0 |
  while IFS= read -r -d '' f; do
    wc -l -- "$f" >> "$tmp"
  done

mv -- "$tmp" "$out_file"
trap - EXIT
printf 'wrote %s\n' "$out_file"
```

## See Also
- `github-master` — running scripts safely in GitHub Actions.
- `docker-expert` — robust container entrypoint scripts.
- `python-expert` — when a script outgrows the shell.

Versions

The database has no other skills named bash-scripting-expert.

Database snapshot: 13.11.2026 · package version fd0b90c9a6fd (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100bash-ops
    Defensive Bash scripting for production automation, CI scripts, and agent-facing tools. Triggers on: bash, shell script, defensive bash, bash strict mode, set -euo pipefail, set -Eeuo pipefail, shellcheck, trap, IFS, cleanup trap, mktemp, getopts, argument parsing, exit codes,…
  • 100bash-shell-scripting-advanced
    Use this skill when writing robust POSIX Bash automation scripts with set -euo pipefail, parameter expansion, and trap handlers.
  • 100bash-scripting
    Expert guidance for writing, hardening, debugging, and reviewing Bash and POSIX shell scripts. Use whenever the user writes, edits, refactors, or pastes a .sh / .bash file or shell snippet; asks for a script, automation, wrapper, installer, backup, deploy, cron, CI/CD, or…
  • 90shell-scripting
    Use when a ticket adds or changes shell scripts — bash automation, CI steps, install or release scripts, git hooks, Makefile recipes — and they must follow the Google Shell Style Guide, be safe under set -euo pipefail (knowing its caveats), quote every expansion, clean up temp…
  • 100bash-expert
    Expert Bash help for writing, debugging, and optimizing safe, portable shell one-liners and scripts on macOS/Linux. Use when users ask for Bash or POSIX sh commands, script reviews, ShellCheck fixes, quoting/pipeline issues, process/file automation, or converting requirements into shell scripts.
  • 90bash
    Bash scripting and CLI operations. Trigger on shell scripts, quoting bugs, set -e, trap, git commands, sandbox failures, or tool-selection between Bash and Glob/Grep.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.