Production-grade Bash fundamentals - syntax, variables, control flow, functions
Writes production-ready Bash scripts with proper syntax, variables, control flow, and error handling. Use when creating or fixing shell scripts that need to be reliable and maintainable.
/plugin marketplace add pluginagentmarketplace/custom-plugin-bash-shell/plugin install custom-plugin-bash-shell@pluginagentmarketplace-bash-shellThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/config.yamlassets/schema.jsonreferences/GUIDE.mdreferences/PATTERNS.mdscripts/validate.pyMaster the fundamentals of Bash shell scripting with production-ready patterns
After completing this skill, you will be able to:
set -euo pipefail)#!/usr/bin/env bash
# Script: example.sh
# Purpose: Demonstrate basic structure
# Usage: ./example.sh [options]
set -euo pipefail # Strict mode
IFS=$'\n\t' # Safe IFS
# Constants
readonly VERSION="1.0.0"
# Main logic
main() {
echo "Hello, World!"
}
main "$@"
# Declaration
name="value" # String
declare -i count=0 # Integer
declare -r CONST="immutable" # Readonly
declare -a array=("a" "b" "c") # Array
declare -A map=([key]="val") # Associative array
# Expansion
echo "${name}" # Basic
echo "${name:-default}" # Default if unset
echo "${name:?error msg}" # Error if unset
echo "${#name}" # Length
echo "${name^^}" # Uppercase
echo "${name,,}" # Lowercase
# Conditionals
if [[ -f "$file" ]]; then
echo "File exists"
elif [[ -d "$file" ]]; then
echo "Directory exists"
else
echo "Not found"
fi
# Case statements
case "$option" in
start) do_start ;;
stop) do_stop ;;
*) echo "Unknown" ;;
esac
# Loops
for item in "${array[@]}"; do
echo "$item"
done
while read -r line; do
process "$line"
done < file.txt
function greet() {
local name="${1:?Name required}"
echo "Hello, $name!"
}
# With return values
function add() {
local a="${1:-0}"
local b="${2:-0}"
echo $((a + b))
}
result=$(add 5 3)
die() {
printf 'ERROR: %s\n' "$1" >&2
exit "${2:-1}"
}
try_command() {
if ! "$@"; then
die "Command failed: $*"
fi
}
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help) usage; exit 0 ;;
-v|--verbose) VERBOSE=true; shift ;;
--) shift; break ;;
-*) die "Unknown option: $1" ;;
*) break ;;
esac
done
| Don't | Do | Why |
|---|---|---|
for f in $(ls) | for f in * | Parsing ls breaks on spaces |
result=`cmd` | result=$(cmd) | Backticks don't nest |
[ $var = x ] | [[ "$var" = x ]] | Unquoted vars break |
cd dir; cmd | (cd dir && cmd) | cd can fail silently |
| Error | Cause | Fix |
|---|---|---|
unbound variable | Using undefined var | Use ${var:-} |
syntax error | Missing quotes | Check bracket matching |
command not found | PATH issue | Use full path |
permission denied | Not executable | chmod +x script |
# Enable trace
set -x
# Verbose PS4
export PS4='+(${BASH_SOURCE}:${LINENO}): '
# Shellcheck
shellcheck script.sh
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.