bash ناجح

Write Bash scripts following best practices. Use when creating shell scripts, automation, or CLI tools. Covers safe scripting patterns.

57من ١٠٠
٨٢
نجوم
٢٢
تنزيلات
٧٤
مشاهدات

// تثبيت المهارة

تثبيت المهارة

المهارات هي كود تابع لأطراف ثالثة من مستودعات GitHub العامة. يفحص SkillHub الأنماط الخبيثة المعروفة، لكنه لا يستطيع ضمان السلامة. راجع الكود المصدري قبل التثبيت.

تثبيت عام (على مستوى المستخدم):

npx skillhub install majiayu000/claude-skill-registry/bash

تثبيت في المشروع الحالي:

npx skillhub install majiayu000/claude-skill-registry/bash --project

skill.install.customTargetHelp

npx skillhub install majiayu000/claude-skill-registry/bash --target-dir /path/to/skills

المسار المقترح: ~/.claude/skills/bash/

مراجعة الذكاء الاصطناعي

57
من ١٠٠
جودة التعليمات58
دقة الوصف50
الفائدة58
السلامة التقنية65

Scored 57 — compact bash reference with genuinely useful patterns (trap cleanup, require_command, log/die functions). Most content is well-known to experienced devs but the patterns are correctly assembled as a reusable template.

betasimpleall-devsbash-scriptingshell-automationcli-tools
تمت المراجعة بواسطة claude-code في 20‏/3‏/2026

محتوى SKILL.md

---
name: bash
description: Write Bash scripts following best practices. Use when creating shell scripts, automation, or CLI tools. Covers safe scripting patterns.
allowed-tools: Read, Write, Edit, Bash, Glob, Grep
---

# Bash Scripting

## Script Template

```bash
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

# Script description
# Usage: ./script.sh <arg1> <arg2>

readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

main() {
    local arg1="${1:-default}"

    # Script logic here
    echo "Running with: $arg1"
}

main "$@"
```

## Safety Settings

```bash
set -e          # Exit on error
set -u          # Error on undefined variables
set -o pipefail # Catch pipe failures
set -x          # Debug: print commands
```

## Variables

```bash
# Declaration
readonly CONST="immutable"
local var="function scoped"

# Default values
name="${1:-default}"      # Use default if unset
name="${1:?Error: missing}"  # Error if unset

# String operations
"${var^^}"    # Uppercase
"${var,,}"    # Lowercase
"${var#prefix}"  # Remove prefix
"${var%suffix}"  # Remove suffix
```

## Conditionals

```bash
# File tests
[[ -f "$file" ]]  # Is file
[[ -d "$dir" ]]   # Is directory
[[ -r "$file" ]]  # Is readable
[[ -x "$file" ]]  # Is executable

# String tests
[[ -z "$var" ]]   # Is empty
[[ -n "$var" ]]   # Is not empty
[[ "$a" == "$b" ]] # Equals

# Numeric tests
(( num > 5 ))     # Greater than
(( num == 5 ))    # Equals
```

## Functions

```bash
log() {
    local level="$1"
    local message="$2"
    echo "[$(date +'%Y-%m-%d %H:%M:%S')] [$level] $message" >&2
}

die() {
    log "ERROR" "$1"
    exit 1
}

require_command() {
    command -v "$1" >/dev/null 2>&1 || die "Required command not found: $1"
}
```

## Error Handling

```bash
# Trap for cleanup
cleanup() {
    rm -rf "$TMP_DIR"
}
trap cleanup EXIT

# Catch errors
if ! result=$(some_command 2>&1); then
    die "Command failed: $result"
fi
```

## Loops

```bash
# For loop
for item in "${array[@]}"; do
    echo "$item"
done

# While read
while IFS= read -r line; do
    echo "$line"
done < file.txt

# Process substitution
while read -r line; do
    echo "$line"
done < <(command)
```

## Best Practices

1. Quote all variables: `"$var"`
2. Use `[[` instead of `[`
3. Use `local` in functions
4. Use `readonly` for constants
5. Always use `set -euo pipefail`
6. Use shellcheck for linting

الترخيص

الترخيص المُعلن: MIT

MIT License

Copyright (c) 2026 majiayu000

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

عرض الترخيص في المستودع المصدريالنسخة المنشورة هناك هي المرجع.