OpenParable
Skip to content
← Back to skills

Shell Scripting

Development
shell-scripting

Shell Scripting is an Agent Skill for development published in the microclaw/microclaw repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

Write robust, safe bash/shell scripts and one-liners, and explain or fix existing ones. Use when users want a shell script, a command pipeline, automation glue, or ask why a bash snippet misbehaves (quoting, globbing, exit codes). Triggers on mentions of bash, shell script, .sh, command line, pipe, one-liner, cron job command, 脚本, 命令行, 管道, shell.

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/microclaw/microclaw/blob/HEAD/skills/built-in/shell-scripting/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/shell-scripting, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

Shell Scripting

Write scripts that fail loudly and safely, not ones that silently do the wrong thing.

Start every script with a strict header

#!/usr/bin/env bash
set -euo pipefail   # exit on error, error on unset var, fail a pipeline if any stage fails
IFS=$'\n\t'

Quoting & safety (the top source of bugs)

  • Always quote expansions: "$var", "${arr[@]}", "$(cmd)" — unquoted values word-split and glob.
  • Use [[ ... ]] over [ ... ] for tests; (( ... )) for arithmetic.
  • Prefer "$(cmd)" over backticks. Check mkdir -p, rm -rf paths twice.
  • Handle filenames with spaces/newlines: find ... -print0 | xargs -0, or while IFS= read -r line.

Common patterns

# Args with defaults
name="${1:-world}"

# Loop over files safely
for f in ./*.log; do [[ -e "$f" ]] || continue; echo "$f"; done

# Trap cleanup on exit
tmp="$(mktemp)"; trap 'rm -f "$tmp"' EXIT

# Check a command exists
command -v jq >/dev/null 2>&1 || { echo "jq required" >&2; exit 1; }

Guidance

  • Run shellcheck script.sh if available — it catches most real bugs.
  • Make scripts idempotent where possible; print what they're doing.
  • Don't parse ls output; glob or use find. Don't eval untrusted input.
  • For anything beyond ~50 lines of logic, consider Python instead.