bash-scripting

Featured

Use when writing or hardening a shell script that must survive another machine — a CI step, install script, cron job, git hook, devcontainer entrypoint: strict-mode leaks, quoting/word-splitting, arrays, trap cleanup, bash-vs-POSIX portability, ShellCheck findings. NOT CI workflow structure, runners, caching or matrix (that is `github-actions`).

AI & Automation 648 stars 89 forks Updated 4 days ago MIT

Install

View on GitHub

Quality Score: 98/100

Stars 20%
94
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Bash scripting — scripts that survive a stranger's machine You are the shell author who has been burned: by an unquoted `"$@"` that exploded a path with spaces, by `rm -rf "$DIR/"` where `$DIR` was empty, by a `trap` that fired twice, by a `set -e` that swore it caught errors and didn't. Write every script as if it will run in CI, in a container, and on a 2014 Mac with `bash 3.2` — because eventually it will. The first decision is not a line of code. It is: **which shell am I targeting?** That choice decides what you are allowed to write. Make it before the shebang. ## The header you start every bash script with ```bash #!/usr/bin/env bash set -euo pipefail # see "Strict mode, honestly" — this is a baseline, not a force field IFS=$'\n\t' # split words on newline/tab only, never on spaces ``` - `#!/usr/bin/env bash` — find bash on `PATH`; do not hardcode `/bin/bash`, which is **3.2** on macOS and may not exist on some images. - `set -e` — exit on an uncaught non-zero command. Leaky (below), still worth having. - `set -u` — error on an unset variable, so a typo'd `$OUPUT` fails loud instead of expanding to empty. - `set -o pipefail` — a pipeline fails if **any** stage fails, not just the last. Bashism — not in POSIX `sh`. - `IFS=$'\n\t'` — stops the classic "unquoted expansion splits on every space" bug at the source. ## Pick your shell first `set -o pipefail`, arrays, `[[ ]]`, and `local` are **bashisms**. If your shebang is `#!/bin/sh` you may not...

Details

Author
ericrisco
Repository
ericrisco/rsc-harness
Created
5 months ago
Last Updated
4 days ago
Language
JavaScript
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category