Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
evansenter avatar

Shell Scripting

  • 1 installs
  • 2 repo stars
  • Updated August 2, 2026
  • evansenter/dotfiles

Applies bash/zsh conventions when writing or editing shell scripts: strict mode, platform detection, idempotency, quoting, and shellcheck compliance.

About

Encodes shell scripting conventions covering headers, macOS/Linux detection, command-availability guards, idempotent operations, path resolution, and variable quoting. A developer follows it whenever writing or editing .sh files, shell functions, or inline bash in Makefiles and CI.

  • set -euo pipefail headers plus platform-aware sed and command guards
  • Requires shellcheck-clean scripts and pwd -P path resolution

Shell Scripting by the numbers

  • 1 all-time installs (skills.sh)
  • Ranked #467 of 550 CLI & Terminal skills by installs in the Skillselion catalog
  • Data as of Aug 3, 2026 (Skillselion catalog sync)
npx skills add https://github.com/evansenter/dotfiles --skill shell-scripting

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1
repo stars2
Last updatedAugust 2, 2026
Repositoryevansenter/dotfiles

What it does

Applies bash/zsh conventions when writing or editing shell scripts: strict mode, platform detection, idempotency, quoting, and shellcheck compliance.

Files

SKILL.mdMarkdownGitHub ↗

Shell Scripting Patterns

This skill auto-applies when writing shell scripts. Follow these conventions.

Script Header

All bash scripts must start with:

#!/bin/bash
set -euo pipefail

Zsh scripts (.zshrc, .zsh_prompt, etc.) don't use set -euo pipefail — it breaks interactive shell behavior.

Platform Detection

if [[ "$(uname)" == "Darwin" ]]; then
    # macOS
else
    # Linux
fi

For commands that differ between platforms (e.g., sed -i on macOS needs ''):

if [[ "$(uname)" == "Darwin" ]]; then
    sed -i '' "s/old/new/" "$file"
else
    sed -i "s/old/new/" "$file"
fi

Command Availability

Always check before using optional commands:

command -v foo >/dev/null 2>&1 && foo_available=true || foo_available=false

# Or for guard clauses:
if ! command -v foo &>/dev/null; then
    echo "Skipping (foo not installed)"
    return 0  # or exit 0 in scripts
fi

Idempotency

Scripts should be safe to run repeatedly:

# Symlinks: -sf overwrites existing
ln -sf "$source" "$dest"

# Directories: -p is no-op if exists
mkdir -p "$dir"

# Only install if missing
if ! command -v foo &>/dev/null; then
    install_foo
fi

Paths

Resolve symlinks when capturing the script's own location — use pwd -P, not pwd. Plain pwd returns the logical path, so a script run via a symlink ends up with a directory string that doesn't match its physical location. If any subsequent code does a same-path guard ([[ "$src" == "$dest" ]]), it fails to fire and the script can overwrite its own source.

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
dest_dir="$(cd "$(dirname "$dest_file")" && pwd -P)"
[[ "$script_dir" == "$dest_dir" ]] && return  # same file, skip

Variables

  • Quote all variable expansions: "$var", "${var}", "$@"
  • Use ${var:-default} for optional variables with defaults
  • Use ${var:?error message} for required variables
  • Use local in functions: local result="$(command)"

Output

  • Use echo for user-facing messages
  • Use >&2 for errors: echo "Error: failed" >&2
  • Silent success is fine for automation scripts
  • Use || true to suppress expected failures

ShellCheck

All .sh files must pass shellcheck. Common directives:

# shellcheck disable=SC2034  # Variable appears unused (but is exported/sourced)
# shellcheck source=/dev/null  # Can't follow dynamic source

Related skills

CLI & Terminalbackenddevops

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.