/linux:linux-bash-scriptingfrom linux
Guides writing and reviewing portable sk-* Bash scripts using common.sh primitives for distro detection, package installs, services, and firewall rules.
Ships in linux. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This meta-skill is how sk-* scripts stay two-family. A script must never
hardcode apt, ufw, or apache2 — it calls the common.sh primitives, which
resolve to the right tool for the detected family (Debian/Ubuntu or the RHEL
family: Fedora, RHEL, CentOS Stream, Rocky, Alma, Oracle).
| Need | Don't hardcode | Use this primitive |
|---|---|---|
| Detect the family | parse /etc/os-release | detect_distro → SK_DISTRO_FAMILY, SK_PKG |
| Install packages | apt install / dnf install | pkg_install <pkg>... |
| Query installed | dpkg -s / rpm -q | pkg_is_installed <pkg> |
| Enable extra repo | add-apt-repository / EPEL | ensure_epel (no-op off-RHEL & on Fedora) |
| Service unit name | apache2 / httpd | svc_name apache |
| Open a firewall port | ufw allow / firewall-cmd | `firewall_allow <port |
| Web config dir / reload | sites-available / conf.d | web_conf_dir, web_reload |
| Gate the script | check $ID | `require_family <debian |
Full contract: references/common-sh-contract.md.
Plan: docs/multi-distro/plan.md.
sk-* script in this repository.scripts/.| Artefact | Source | Required? | If absent |
|---|---|---|---|
| Target skill, script name, and inventory entry | Request and script inventory | yes | Stop before scaffolding an unowned script |
| Behaviour, inputs, decision flags, and side effects | Operator and owning specialist skill | yes | Produce a review/questions list; do not invent defaults |
| Distro support and service/package mappings | Owning skill and common.sh contract | yes | Require any only when both families are verified |
| Test fixtures and mutation authority | Maintainer and safe test host | for execution | Limit work to static review and dry-run design |
Review uses read/search access and is read-only by default. Editing an owned script requires explicit implementation authority; executing privileged or destructive paths requires separate test-host approval. Never use production state to discover what an unsafe script does.
Without shellcheck, a Bash runtime, root, or both distro families, complete static checks and label runtime, privilege, or family behaviour unassessed. Do not claim portability or safety from source inspection alone.
| Choice | Action | Failure avoided |
|---|---|---|
| Input requires a prompt | Add a named decision flag and require_flag under --yes | Invented unattended defaults |
| Operation changes important config | Backup, atomic write, native validation, then reload | Partial config and outage |
| Package/service differs by family | Use common.sh primitive | Debian-only automation |
| Operation is destructive | Typed confirmation plus explicit non-interactive flag | Accidental deletion |
For every mutating sk-* script, apply the safe reversible operations standard: detect the family, capture a before state, support a dry-run or no-op path, make the operation idempotent, use atomic writes where files change, preserve ownership/labels, and expose a bounded rollback or recovery path. A script is not release-ready until its success path, already-correct path, invalid-input path, and rollback/recovery evidence are tested for both distro families or explicitly marked unassessed.
common.sh contract.--yes, dry run, interruption, idempotency, and both families where claimed.| Artefact | Acceptance |
|---|---|
| Script validation evidence | Includes shellcheck/engine lint, help, dry run, negative paths, distro matrix, diff, and manifest alignment |
common.sh is mandatory; do not reinvent shared behavior.common.sh. Fix: use its output, guard, package, service, and file primitives.--yes as permission to invent defaults. Fix: require every decision flag.set -e. Fix: handle expected failures and preserve set -uo pipefail.sk-* or copy it to ~/<name>.sh (see "Handing a script to a user").| Artefact | Consumer | Acceptance condition |
|---|---|---|
| Conforming script or review | Maintainer | Contract, flags, safety, and family rules are satisfied |
| Test evidence | Reviewer | Covers help, errors, dry run, destructive gates, and lint |
| Manifest update | Installer | Script source, name, core status, and purpose agree |
For sk-cifs-mount, make share, mount point, and credentials source explicit flags. Under --yes, missing any required choice exits 2; dry run prints package, credential-file, mount, and fstab actions without exposing the password or writing files.
../../docs/continuous-improvement/safe-reversible-operations-standard.md
../../docs/continuous-improvement/two-family-validation-and-recovery.md
This skill is the foundation every other script in linux-skills is built on.
Before writing a new sk-* script, or reviewing an existing one, load this
skill.
It defines:
common.sh library contract (what functions exist, what they do).Read the full engine spec in docs/engine-design/spec.md
and the script catalogue in docs/engine-design/script-inventory.md
for context.
scripts/.common.sh.grep).Every sk-* script must start from this six-section layout. See
references/script-template.sh for a
copy-pasteable version. The sk-new-script wrapper is not shipped in this
checkout; copy and adapt the reference template manually into the owning
skill's scripts/ directory.
The six sections in order:
#: prefixed comments with Title, Synopsis,
Description, Author, Contact, Version. Grep-extractable. Author line must
always read #: Author: Peter Bamuhigire <techguypeter.com>.set -uo pipefail then source of common.sh.
Never use set -e (it interacts badly with traps and function return
codes).usage() that prints every flag the
script accepts.parse_standard_flags "$@", then parse
script-specific decision flags from REMAINING_ARGS.require_root, require_family <debian|rhel|any>,
require_cmd, and any require_flag calls for --yes mode.header, pass, warn, fail,
info, and run.common.sh library contractcommon.sh is the shared library every script sources from
/usr/local/lib/linux-skills/common.sh. The full function contract lives in
references/common-sh-contract.md — read
it before calling a new function. Summary:
| Function | Purpose |
|---|---|
pass "msg" | Green [PASS] line; increments PASS_COUNT. |
warn "msg" | Yellow [WARN] line; increments WARN_COUNT. |
fail "msg" | Red [FAIL] line; increments FAIL_COUNT. |
info "msg" | Cyan [INFO] line; no count. |
header "Section" | Bold section separator. |
die "msg" [exit_code] | Red error to stderr, exit with code (default 1). |
log "msg" | Timestamped line to log file (if --log). |
Always use these. Never roll your own echo -e "\033[31m...".
| Function | Purpose |
|---|---|
require_root | Exit 1 if not root. |
require_family <debian|rhel|any> | Exit 3 if the detected family isn't allowed. Gate a script to one family, or pass any for both. Prefer this over the legacy require_debian. |
require_cmd <cmd>... | Exit 5 if any command is missing; names the package. |
require_flag <NAME> | Under --yes, exit 2 if the named global variable is empty. |
--yes)| Function | Purpose |
|---|---|
confirm "Do X?" [default=N] | yes/no; default = N. Auto-yes under --yes only for non-destructive confirms. |
confirm_destructive "About to DELETE X" | Requires typed yes, not y. Under --yes, requires a decision flag — never auto-confirms. |
prompt "Label" [default] [validator] | Single-value read with optional default + validator. |
select_one "Label" opt1 opt2... | Numeric menu; returns chosen value. |
| Function | Purpose |
|---|---|
safe_tempfile [prefix] | mktemp + trap cleanup. Returns path. |
safe_tempdir [prefix] | As above, directory. |
atomic_write <target> | Reads stdin into a unique sibling temporary file, then renames. Rejects symlink/non-regular targets and metadata errors; preserves mode/owner. |
backup_file <path> | Copies to <path>.bak-YYYYMMDD-HHMMSS. Prints backup path. |
sk_source_trusted_config <file> | Sources a config file only if root/the caller owns it, it is not group/world-writable or a symlink, and its directory is likewise. Returns 0 loaded, 1 absent, 2 refused. Never source a config path directly. |
| Function | Purpose |
|---|---|
parse_standard_flags "$@" | Consumes standard flags, sets DRY_RUN, YES, LOG_FILE, JSON, VERBOSE, QUIET. Leaves unknown args in REMAINING_ARGS. |
run <cmd>... | Prints the command. In --dry-run, prints and skips. |
Every script must support these flags via parse_standard_flags:
| Flag | Meaning |
|---|---|
--help, -h | Print usage() and exit 0. Must list every decision flag. |
--version | Print version and exit 0. |
--yes, -y | Non-interactive. Errors if a required decision flag is missing — never silently defaults. |
--dry-run, -n | Print every action, change nothing. |
--log[=PATH] | Tee output to /var/log/linux-skills/<script>-YYYYMMDD-HHMMSS.log. |
--json | Machine-readable output (where meaningful). No colors. |
--verbose, -v | Extra diagnostics. |
--quiet, -q | Errors and final result only. Incompatible with -v. |
--yes contract (non-negotiable)--yes means "the caller has pre-committed to every decision". It does
not mean "accept safe defaults." If a script would normally prompt for a
required input and the caller did not supply a flag for it, the script must
abort:
ERROR: --yes was passed but --domain is required.
Run `<script> --help` to see required flags.
This rule exists because Claude Code invokes scripts non-interactively and must get exactly the outcome it asked for — silent defaults are a footgun.
When running interactively (no --yes), scripts must feel friendly at a
terminal. See references/interactive-ux.md
for the full rule set. Key points:
header to mark phases.pass, warn, fail,
info — never ad-hoc echo.sk-* script, a config file, a man page).confirm_destructive, which requires the user to type yes.Ctrl-C is a first-class exit path. The trap installed by common.sh
ensures a clean exit. Don't fight it.These are required review rules, but the sk-lint wrapper and its pre-commit
hook are not shipped in this checkout. Check them manually and use the
available shell and engine validators before merging.
common.sh — never reimplement colors, prompts, traps.set -uo pipefail — always. Never set -e."$var", "${array[@]}", always.IFS= read -r — every read, every time.${var##*/} for basename,
${var%.*} for removing a suffix. Faster and safer than subprocessing..new path or > file
on anything important. Use atomic_write or backup_file first.safe_tempfile, which auto-registers a cleanup trap.case, not sprawling regex — from Pro Bash. Easier to
read, easier to extend, easier to debug.printf over echo — printf '%s\n' "$var". echo's behavior varies."$@" (quoted) when forwarding args. Unquoted $@ word-splits.0 success, 1 generic failure, 2
usage/flag error, 3 precondition failed, 4 user aborted, 5
dependency missing.eval untrusted input. No exceptions.nginx -t, apache2ctl configtest, visudo -c, sshd -t, named-checkconf. Every time./var/log/linux-skills/<script>.log regardless of --log.shellcheck with zero warnings. Run
shellcheck <script> and bash -n <script> before committing.Applies whenever the user, not Claude, is asked to run a script, typically because it needs root or a password Claude cannot supply. The command the user types must be one line and as short as the path allows.
sk-* command first. Check command -v sk-foo. If absent, give
sudo install-skills-bin <skill-name> once; the user then runs sudo sk-foo.
A bare name on PATH is the shortest possible path.bash -n, and for a read-only script a grep for mutating verbs), then copy
it to ~/<short-name>.sh. The user runs sudo bash ~/<short-name>.sh. Never
hand over the scratch, temp, or skill-directory path.$(dirname "$(readlink -f "$0")")/<short-name>.out, mode 600, owned by
$SUDO_USER. Redact password hashes and secrets in that output. Because the
output goes to a file, print one line to the terminal before redirecting
(writing to <file>) and one when finished; a script that stays silent looks
like one that failed.&& chains, heredocs, or wrapped
paths. In Claude Code, tell the user to type ! first and to copy only the
line inside the code block, not the fences.sha256sum ~/<short-name>.sh so the user can confirm the file
was not altered after validation, and give
rm ~/<short-name>.sh ~/<short-name>.out for afterwards.Machine-run commands (cloud-init runcmd, cron, systemd units) are exempt.
When Claude Code is asked to do something that maps to a script in this toolkit, it must:
command -v sk-foo to see if the script is
installed. If not, suggest sudo install-skills-bin <skill-name>.sk-foo --help to see the required decision flags.--yes and hope a default saves the day.--dry-run --yes --<flags>
to preview.--yes --log --<flags>.--json is
supported, use it.If any step of this loop isn't possible (e.g. the script doesn't have the flag we need), that's a script bug — file it against the inventory, not a silent workaround.
references/script-template.sh — the canonical six-section template.references/common-sh-contract.md — full function contract for the shared library.references/interactive-ux.md — interactive UX rules in detail.docs/engine-design/spec.md — the binding engine specification.docs/engine-design/script-inventory.md — the curated catalogue.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
bash, shell-scripting, multi-distro, common-sh, script-review
npx claudepluginhub peterbamuhigire/linux-skills --plugin linux45 skills in this plugin
/cisco-ios-patternsUse when reading or reviewing Cisco IOS/IOS-XE configuration, selecting read-only show commands, or planning and verifying bounded router or switch configuration work. Not for Linux host networking, bulk SSH automation, or config preflight parsing; route those to linux-network-admin, netmiko-ssh-automation, or network-config-validation./linux-access-controlUse when creating, revoking, or auditing Linux users, groups, SSH keys, sudo/wheel access, PAM settings, SELinux user mappings, or file permissions. Use linux-secrets for credential material and linux-server-hardening for broader host policy./linux-archive-integrityUse when creating, signing, encrypting, listing, comparing, or restoring metadata-preserving tar archives on Debian/Ubuntu or RHEL-family hosts. Covers ACLs, xattrs, incrementals, and verification; use linux-rsync-sync for file-tree mirrors./linux-auditd-rulesUse when inspecting, designing, testing, persisting, or querying auditd rules for forensic attribution on Debian/Ubuntu or RHEL-family hosts. Covers watches, syscalls, loss, and immutable mode; use linux-file-integrity for drift and linux-benchmark-scanning for scoring./linux-benchmark-scanningUse when running read-only OpenSCAP or Lynis scans, selecting distro-matched profiles, interpreting failures, or drafting remediation on Debian/Ubuntu or RHEL-family hosts. Use linux-auditd-rules for attribution and linux-file-integrity for AIDE drift./linux-cloud-initUse when authoring, validating, or debugging cloud-init user-data, Ubuntu autoinstall, or RHEL-family Kickstart for first-boot provisioning. Use linux-server-provisioning for interactive post-boot setup and linux-config-management for ongoing desired state.Other plugins' skills for the same job