Marketplace shell-scripting
Specialized knowledge of Bash and Zsh scripting, shell automation, command-line tools, and scripting best practices. Use when the user needs to write, debug, or optimize shell scripts, work with command-line tools, automate tasks with bash/zsh, or asks for shell script help.
install
source · Clone the upstream repo
git clone https://github.com/aiskillstore/marketplace
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/aiskillstore/marketplace "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/codingkaiser/shell-scripting" ~/.claude/skills/aiskillstore-marketplace-shell-scripting-440600 && rm -rf "$T"
manifest:
skills/codingkaiser/shell-scripting/SKILL.mdsource content
Shell Scripting Expert
Expert guidance for writing robust, maintainable Bash and Zsh scripts with best practices for automation and command-line tool usage.
Script Structure Essentials
Start every script with:
#!/usr/bin/env bash set -euo pipefail IFS=$'\n\t'
: Exit on errorset -e
: Error on undefined variablesset -u
: Catch errors in pipesset -o pipefail
: Safer word splittingIFS=$'\n\t'
Critical Best Practices
- Always quote variables:
not"$variable"$variable - Use
for conditionals (Bash):[[if [[ "$var" == "value" ]]; then - Check command existence:
if command -v git &> /dev/null; then - Avoid parsing
: Use globs orls
insteadfind - Use arrays for lists:
not space-separated stringsfiles=("file1" "file2") - Handle errors with traps:
trap cleanup EXIT trap 'echo "Error on line $LINENO"' ERR
Common Patterns
Argument Parsing
while [[ $# -gt 0 ]]; do case $1 in -h|--help) usage; exit 0 ;; -v|--verbose) VERBOSE=true; shift ;; -*) echo "Unknown option: $1"; exit 1 ;; *) break ;; esac done
Safe File Iteration
# Prefer this (handles spaces, newlines correctly): while IFS= read -r -d '' file; do echo "Processing: $file" done < <(find . -type f -name "*.txt" -print0) # Or with simple globs: for file in *.txt; do [[ -e "$file" ]] || continue # Skip if no matches echo "Processing: $file" done
User Confirmation
read -rp "Continue? [y/N] " response if [[ "$response" =~ ^[Yy]$ ]]; then echo "Continuing..." fi
Colored Output
RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${GREEN}Success${NC}" echo -e "${RED}Error${NC}" >&2
Modern Tool Alternatives
When appropriate, suggest these modern replacements:
(rg) → faster than grepripgrep
→ faster than findfd
→ interactive filteringfzf
→ JSON processingjq
→ YAML processingyq
→ cat with syntax highlightingbat
→ enhanced lseza
Function Organization
usage() { cat <<EOF Usage: ${0##*/} [OPTIONS] <args> Description of what this script does. OPTIONS: -h, --help Show this help -v, --verbose Verbose output EOF } main() { # Main logic here : }
Zsh-Specific Features
When user specifies Zsh:
- Advanced globbing:
(recursive),**/*.txt
(exclude pattern)*.txt~*test* - Parameter expansion:
(uppercase),${var:u}
(lowercase)${var:l} - Associative arrays:
typeset -A hash; hash[key]=value - Extended globbing: Enable with
setopt extended_glob
Security Considerations
- Never
untrusted inputeval - Validate user input before use
- Use
for temporary files:mktempTEMP_FILE=$(mktemp) - Be explicit with
operationsrm -rf - Check for TOCTOU (Time-Of-Check-Time-Of-Use) race conditions
- Don't store secrets in scripts; use environment variables or secret managers
Performance Tips
- Use built-ins over external commands (
vs[[ ]]
,test
vs$(( ))
)expr - Avoid unnecessary subshells:
→var=$(cat file)var=$(<file) - Use
notread
:cat | whilewhile read -r line; do ... done < file - Consider
or GNUxargs -P
for parallel processingparallel
Quick Reference Template
See references/template.sh for a complete, production-ready script template with all best practices incorporated.