Bash

From meowgorithm/dotfiles · View interactive version

Bash is an AI agent skill from the GitHub repository meowgorithm/dotfiles. Create, edit, and improve bash scripts with automated linting and formatting. Use when working with shell scripts (.sh files), writing bash functions, fixing script errors, or when the user asks to create or modify any bash/shell script.

How to use this skill

Skill file

Bash

Write robust, well-formatted bash scripts with automated quality checks.

Workflow

  1. Before writing: Format with shfmt -w <file> if available
  2. After writing: Lint with shellcheck <file> if available
  3. Iterate: Fix errors, re-format if needed

Formatting with shfmt

Always format before writing if shfmt is installed:

shfmt -w script.sh

Default style (POSIX-compatible):

Options:

Linting with shellcheck

Run after writing/modifying scripts:

shellcheck script.sh

Common issues to address:

Best Practices

Shebang and Headers

#!/usr/bin/env bash
set -euo pipefail

Error Handling

# Check command success
if ! command -v foo &>/dev/null; then
    echo "error: foo not found" >&2
    exit 1
fi

# Safe cd
cd "$DIR" || exit 1

Variables

# Quote all variables
"$VAR"
"${ARRAY[@]}"

# Prefer local
local var="value"

# Defaults
: "${VAR:=default}"

Functions

my_func() {
    local arg1="$1"
    # ...
}

Conditionals

# Prefer [[ ]] over [ ]
[[ -f "$file" ]]

# String matching
[[ "$str" == *pattern* ]]

Pipes

# Use pipefail to catch errors in pipelines
set -o pipefail
cmd1 | cmd2
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.