Bash Scripting Script Template Safety Settings Variables Conditionals Functions Error Handling Loops Best Practices 1. Quote all variables: 2. Use instead of 3. Use in functions 4. Use for constants 5. Always use 6. Use shellcheck for linting ---

\\n\\t'\n\n# Script description\n# Usage: ./script.sh \u003carg1> \u003carg2>\n\nreadonly SCRIPT_DIR=\"$(cd \"$(dirname \"${BASH_SOURCE[0]}\")\" && pwd)\"\n\nmain() {\n local arg1=\"${1:-default}\"\n\n # Script logic here\n echo \"Running with: $arg1\"\n}\n\nmain \"$@\"\n```\n\n## Safety Settings\n\n```bash\nset -e # Exit on error\nset -u # Error on undefined variables\nset -o pipefail # Catch pipe failures\nset -x # Debug: print commands\n```\n\n## Variables\n\n```bash\n# Declaration\nreadonly CONST=\"immutable\"\nlocal var=\"function scoped\"\n\n# Default values\nname=\"${1:-default}\" # Use default if unset\nname=\"${1:?Error: missing}\" # Error if unset\n\n# String operations\n\"${var^^}\" # Uppercase\n\"${var,,}\" # Lowercase\n\"${var#prefix}\" # Remove prefix\n\"${var%suffix}\" # Remove suffix\n```\n\n## Conditionals\n\n```bash\n# File tests\n[[ -f \"$file\" ]] # Is file\n[[ -d \"$dir\" ]] # Is directory\n[[ -r \"$file\" ]] # Is readable\n[[ -x \"$file\" ]] # Is executable\n\n# String tests\n[[ -z \"$var\" ]] # Is empty\n[[ -n \"$var\" ]] # Is not empty\n[[ \"$a\" == \"$b\" ]] # Equals\n\n# Numeric tests\n(( num > 5 )) # Greater than\n(( num == 5 )) # Equals\n```\n\n## Functions\n\n```bash\nlog() {\n local level=\"$1\"\n local message=\"$2\"\n echo \"[$(date +'%Y-%m-%d %H:%M:%S')] [$level] $message\" >&2\n}\n\ndie() {\n log \"ERROR\" \"$1\"\n exit 1\n}\n\nrequire_command() {\n command -v \"$1\" >/dev/null 2>&1 || die \"Required command not found: $1\"\n}\n```\n\n## Error Handling\n\n```bash\n# Trap for cleanup\ncleanup() {\n rm -rf \"$TMP_DIR\"\n}\ntrap cleanup EXIT\n\n# Catch errors\nif ! result=$(some_command 2>&1); then\n die \"Command failed: $result\"\nfi\n```\n\n## Loops\n\n```bash\n# For loop\nfor item in \"${array[@]}\"; do\n echo \"$item\"\ndone\n\n# While read\nwhile IFS= read -r line; do\n echo \"$line\"\ndone \u003c file.txt\n\n# Process substitution\nwhile read -r line; do\n echo \"$line\"\ndone \u003c \u003c(command)\n```\n\n## Best Practices\n\n1. Quote all variables: `\"$var\"`\n2. Use `[[` instead of `[`\n3. Use `local` in functions\n4. Use `readonly` for constants\n5. Always use `set -euo pipefail`\n6. Use shellcheck for linting\n---","attachment_filenames":[],"attachments":[],"content_json":{"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"text":"Bash Scripting","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Script Template","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"#!/usr/bin/env bash\nset -euo pipefail\nIFS=

Bash Scripting Script Template Safety Settings Variables Conditionals Functions Error Handling Loops Best Practices 1. Quote all variables: 2. Use instead of 3. Use in functions 4. Use for constants 5. Always use 6. Use shellcheck for linting ---

\\n\\t'\n\n# Script description\n# Usage: ./script.sh \u003carg1> \u003carg2>\n\nreadonly SCRIPT_DIR=\"$(cd \"$(dirname \"${BASH_SOURCE[0]}\")\" && pwd)\"\n\nmain() {\n local arg1=\"${1:-default}\"\n\n # Script logic here\n echo \"Running with: $arg1\"\n}\n\nmain \"$@\"","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Safety Settings","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"set -e # Exit on error\nset -u # Error on undefined variables\nset -o pipefail # Catch pipe failures\nset -x # Debug: print commands","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Variables","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"# Declaration\nreadonly CONST=\"immutable\"\nlocal var=\"function scoped\"\n\n# Default values\nname=\"${1:-default}\" # Use default if unset\nname=\"${1:?Error: missing}\" # Error if unset\n\n# String operations\n\"${var^^}\" # Uppercase\n\"${var,,}\" # Lowercase\n\"${var#prefix}\" # Remove prefix\n\"${var%suffix}\" # Remove suffix","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Conditionals","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"# File tests\n[[ -f \"$file\" ]] # Is file\n[[ -d \"$dir\" ]] # Is directory\n[[ -r \"$file\" ]] # Is readable\n[[ -x \"$file\" ]] # Is executable\n\n# String tests\n[[ -z \"$var\" ]] # Is empty\n[[ -n \"$var\" ]] # Is not empty\n[[ \"$a\" == \"$b\" ]] # Equals\n\n# Numeric tests\n(( num > 5 )) # Greater than\n(( num == 5 )) # Equals","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Functions","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"log() {\n local level=\"$1\"\n local message=\"$2\"\n echo \"[$(date +'%Y-%m-%d %H:%M:%S')] [$level] $message\" >&2\n}\n\ndie() {\n log \"ERROR\" \"$1\"\n exit 1\n}\n\nrequire_command() {\n command -v \"$1\" >/dev/null 2>&1 || die \"Required command not found: $1\"\n}","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Error Handling","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"# Trap for cleanup\ncleanup() {\n rm -rf \"$TMP_DIR\"\n}\ntrap cleanup EXIT\n\n# Catch errors\nif ! result=$(some_command 2>&1); then\n die \"Command failed: $result\"\nfi","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Loops","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"# For loop\nfor item in \"${array[@]}\"; do\n echo \"$item\"\ndone\n\n# While read\nwhile IFS= read -r line; do\n echo \"$line\"\ndone \u003c file.txt\n\n# Process substitution\nwhile read -r line; do\n echo \"$line\"\ndone \u003c \u003c(command)","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Best Practices","type":"text"}]},{"type":"ordered_list","attrs":{"order":1,"listStyle":"number"},"content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Quote all variables: ","type":"text"},{"text":"\"$var\"","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Use ","type":"text"},{"text":"[[","type":"text","marks":[{"type":"code_inline"}]},{"text":" instead of ","type":"text"},{"text":"[","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Use ","type":"text"},{"text":"local","type":"text","marks":[{"type":"code_inline"}]},{"text":" in functions","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Use ","type":"text"},{"text":"readonly","type":"text","marks":[{"type":"code_inline"}]},{"text":" for constants","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Always use ","type":"text"},{"text":"set -euo pipefail","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Use shellcheck for linting","type":"text"}]}]}]},{"type":"hr","attrs":{"markup":"---"}}]},"metadata":{"date":"2026-06-05","name":"bash","author":"@skillopedia","source":{"stars":95,"repo_name":"claude-agentic-framework","origin_url":"https://github.com/dralgorhythm/claude-agentic-framework/blob/HEAD/.claude/skills/languages/bash/SKILL.md","repo_owner":"dralgorhythm","body_sha256":"36f2ae61c1a3361e777a816a80ddc8ab2bc57a61a34d59a2cd0b76f604f696fd","cluster_key":"ef666757a73a81bd41cb41b388c05a0cd3717f0bed73aed22ab8a415e7e89aa6","clean_bundle":{"format":"clean-skill-bundle-v1","source":"dralgorhythm/claude-agentic-framework/.claude/skills/languages/bash/SKILL.md","bundle_sha256":"6596f70e96bf60c08ca76bfac864fc20f0804198bf8157ae173ce417eb31d2ae","attachment_count":0,"text_attachments":0,"binary_attachments":0},"cluster_size":1,"skill_md_path":".claude/skills/languages/bash/SKILL.md","import_metadata":{"date":"2026-06-05","author":"@skillopedia","version":"v1","category":"general","category_label":"General"},"exact_dupes_collapsed_into_this":0},"version":"v1","category":"general","import_tag":"clean-skills-v1","description":"Write Bash scripts following best practices. Use when creating shell scripts, automation, or CLI tools. Covers safe scripting patterns."}},"renderedAt":1782979263645}

Bash Scripting Script Template Safety Settings Variables Conditionals Functions Error Handling Loops Best Practices 1. Quote all variables: 2. Use instead of 3. Use in functions 4. Use for constants 5. Always use 6. Use shellcheck for linting ---