bash-pro
Écrire des scripts Bash prêts pour la production
L'écriture de scripts Bash sûrs et testables pour l'automatisation nécessite des patterns de programmation défensive. Cette compétence fournit une guidance d'expert sur la gestion stricte des erreurs, la validation sécurisée des entrées, les tests avec Bats, et l'intégration CI/CD.
下載技能 ZIP
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
開啟並開始使用
測試它
正在使用「bash-pro」。 Write a script that backs up a directory with timestamped archives
預期結果:
A complete Bash script with: set -Eeuo pipefail strict mode, getopts for -s (source) -d (destination) -h (help), timestamped backup filenames, tar with proper error handling, cleanup trap for temp files, dry-run mode with DRY_RUN variable, and comprehensive --help output
正在使用「bash-pro」。 Create a script to monitor disk usage and alert when above threshold
預期結果:
A monitoring script with: df command parsing, threshold validation, structured logging with timestamps, syslog integration, graceful handling of missing commands, and configurable alert levels via environment variables
安全審計
安全This is a prompt-only skill that provides guidance on defensive Bash scripting. Static analysis scanned 0 files (0 lines) and detected no suspicious patterns or risk factors. The skill contains no executable code and only provides instructional content for writing safe, production-grade shell scripts. No command injection, credential access, or malicious patterns detected.
你能建構什麼
Ingénieur DevOps créant des scripts CI/CD
Créer des scripts de déploiement et de construction robustes qui gèrent les erreurs avec élégance, nettoient les ressources temporaires et s'intègrent à GitHub Actions pour les tests automatisés.
Développeur écrivant des utilitaires système
Construire des outils en ligne de commande avec une documentation d'aide appropriée, une validation des arguments et une journalisation permettant une utilisation sûre en environnement de production.
Ingénieur SRE examinant des scripts shell
Auditer les scripts Bash existants pour les vulnérabilités de sécurité, les problèmes de portabilité et la conformité aux meilleures pratiques en utilisant ShellCheck et des patterns de programmation défensive.
試試這些提示
Write a Bash script that [describe the task]. Include strict mode, argument parsing with getopts, proper error handling, and a --help option.
Create a GitHub Actions workflow that lints Bash scripts with ShellCheck, formats with shfmt, and runs Bats tests. Include matrix testing across multiple Bash versions.
Write a Bash script that safely processes files from user input. Include proper quoting, temp file cleanup with traps, input validation, and NUL-safe file handling.
Review this Bash script for security issues, error handling gaps, and portability problems. Identify specific ShellCheck warnings and provide fixes: [paste script here]
最佳實務
- Always enable strict mode at script start: set -Eeuo pipefail to catch errors and undefined variables
- Quote all variable expansions: use "$var" not $var to prevent word splitting and globbing
- Use traps for cleanup: trap 'rm -rf "$tmpdir"' EXIT ensures temp files are always removed
避免
- Using for f in $(ls ...) - causes word splitting bugs; use find with -print0 and read -r -d '' instead
- Ignoring exit codes with | pipefail disabled - always check set -o pipefail and verify critical command exits
- Using eval on user input - severe security risk; use arrays for dynamic command construction instead