
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-scriptingAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 1 |
|---|---|
| repo stars | ★ 2 |
| Last updated | August 2, 2026 |
| Repository | evansenter/dotfiles ↗ |
What it does
Applies bash/zsh conventions when writing or editing shell scripts: strict mode, platform detection, idempotency, quoting, and shellcheck compliance.
Files
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 pipefailZsh 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
fiFor 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"
fiCommand 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
fiIdempotency
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
fiPaths
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, skipVariables
- Quote all variable expansions:
"$var","${var}","$@" - Use
${var:-default}for optional variables with defaults - Use
${var:?error message}for required variables - Use
localin functions:local result="$(command)"
Output
- Use
echofor user-facing messages - Use
>&2for errors:echo "Error: failed" >&2 - Silent success is fine for automation scripts
- Use
|| trueto 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