Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

Back to skills

Shell Scripting

ASecurity

Shell scripting best practices for cross-platform CLI tools

288 stars
0 votes
0 copies
2 views
Added 2/6/2026
developmentgoshellbashtestingrefactoringgit

Works with

terminalcli

Security Analysis

A100/100

Scanned 2/10/2026

Install to Claude Code

$npx -y skills add mylee04/code-notify --skill shell-scripting --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Shell Scripting?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Shell Scripting
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mylee04-shell-scripting/badge)](https://www.skillsdirectory.com/skills/mylee04-shell-scripting)

More formats (shields.io, HTML) on the badges page.

Download Zip
Files
SKILL.md
---
name: shell-scripting
description: Shell scripting best practices for cross-platform CLI tools
---

# Shell Scripting Standards

## When to Use

- Writing new shell scripts
- Refactoring existing scripts
- Adding new functions

## Script Structure

### 1. File Header

```bash
#!/bin/bash

# Script description
# https://github.com/mylee04/code-notify

set -e  # Exit on error
```

### 2. Constants (UPPER_CASE)

```bash
VERSION="1.2.0"
CONFIG_DIR="$HOME/.claude"
DEFAULT_SOUND="Glass"
```

### 3. Functions (snake_case)

```bash
# Description of function
# Arguments: $1 = name, $2 = optional value
function_name() {
    local name="$1"
    local value="${2:-default}"

    # Function body
}
```

### 4. Main Logic

```bash
# Main execution
main() {
    validate_args "$@"
    do_work
    cleanup
}

main "$@"
```

## Best Practices

### Variable Handling

```bash
# Good - quoted variables
echo "$message"
path="$HOME/.config"

# Bad - unquoted
echo $message
path=$HOME/.config
```

### Conditionals

```bash
# Good - double brackets
if [[ -n "$var" ]]; then
    echo "not empty"
fi

# Bad - single brackets
if [ -n "$var" ]; then
    echo "not empty"
fi
```

### Command Existence Check

```bash
# Good
if command -v terminal-notifier &> /dev/null; then
    terminal-notifier -message "Hello"
fi

# Bad
if which terminal-notifier; then
    terminal-notifier -message "Hello"
fi
```

### Error Handling

```bash
# Good - explicit error handling
if ! some_command; then
    echo "Error: command failed" >&2
    exit 1
fi

# Good - trap for cleanup
cleanup() {
    rm -f "$temp_file"
}
trap cleanup EXIT
```

### Local Variables in Functions

```bash
# Good
my_function() {
    local input="$1"
    local result
    result=$(process "$input")
    echo "$result"
}

# Bad - pollutes global scope
my_function() {
    input="$1"
    result=$(process "$input")
    echo "$result"
}
```

## Common Patterns

### OS Detection

```bash
detect_os() {
    case "$(uname -s)" in
        Darwin*)    echo "macos" ;;
        Linux*)     echo "linux" ;;
        CYGWIN*|MINGW*|MSYS*) echo "windows" ;;
        *)          echo "unknown" ;;
    esac
}
```

### Safe File Operations

```bash
# Create directory if not exists
mkdir -p "$dir"

# Safe file reading
if [[ -f "$config_file" ]]; then
    config=$(cat "$config_file")
fi

# Atomic write
echo "$content" > "$file.tmp" && mv "$file.tmp" "$file"
```

### JSON Handling (without jq)

```bash
# Simple grep-based check
if grep -q '"enabled":\s*true' "$file"; then
    echo "enabled"
fi

# With jq (if available)
if command -v jq &> /dev/null; then
    value=$(jq -r '.key' "$file")
fi
```

## Testing

### Test Function Output

```bash
test_detect_os() {
    result=$(detect_os)
    if [[ "$result" != "macos" ]] && [[ "$result" != "linux" ]]; then
        echo "FAIL: unexpected OS: $result"
        return 1
    fi
    echo "PASS"
}
```

### Test Exit Codes

```bash
test_error_handling() {
    if invalid_command 2>/dev/null; then
        echo "FAIL: should have failed"
        return 1
    fi
    echo "PASS"
}
```

## Success Metrics

- shellcheck passes with no warnings
- All functions use local variables
- All variables are quoted
- Commands existence checked before use
- Error handling for all failure points

Attribution

mylee04mylee04
View sourceMore from mylee04 →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

284072 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2192 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Tanstack Start

Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...

9881 votes

Pentest

PTES-aligned adversarial security audit for backend, frontend, and mobile applications. Produces a CVSS-scored Hacker Report with verified PoCs and phased remediation.

5491 votes
View all in development →