bash-defensive-patterns
하는 일
이 안내서는 더 안전하고 신뢰할 수 있는 자동화 스크립트(Bash)를 작성하는 방법을 가르칩니다. 흔한 오류를 막고, 예상치 못한 상황에서도 스크립트가 올바르게 작동하도록 돕습니다.
사용하는 경우
- ✓업무의 중요한 작업을 자동화하는 스크립트를 만들 때.
- ✓개발 과정(CI/CD)의 자동화 단계를 만들 때.
- ✓매우 신뢰할 수 있어야 하는 시스템 도구를 개발할 때.
스킬 링크
https://github.com/wshobson/agents/blob/main/plugins/shell-scripting/skills/bash-defensive-patterns/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“파일이 없어도 실패하지 않는 Bash 스크립트는 어떻게 쓸 수 있나요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
안전 모드(`set -euo pipefail`)를 켜고, 변수는 항상 따옴표(`"$variable"`)로 보호하며, 명령이 성공했는지 확인하는 등의 기법을 사용합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Bash Defensive Patterns
Comprehensive guidance for writing production-ready Bash scripts using defensive programming techniques, error handling, and safety best practices to prevent common pitfalls and ensure reliability.
When to Use This Skill
- Writing production automation scripts
- Building CI/CD pipeline scripts
- Creating system administration utilities
- Developing error-resilient deployment automation
- Writing scripts that must handle edge cases safely
- Building maintainable shell script libraries
- Implementing comprehensive logging and monitoring
- Creating scripts that must work across different platforms
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices Summary
- Always use strict mode -
set -Eeuo pipefail - Quote all variables -
"$variable"prevents word splitting - Use [[]] conditionals - More robust than [ ]
- Implement error trapping - Catch and handle errors gracefully
- Validate all inputs - Check file existence, permissions, formats
- Use functions for reusability - Prefix with meaningful names
- Implement structured logging - Include timestamps and levels
- Support dry-run mode - Allow users to preview changes
- Handle temporary files safely - Use mktemp, cleanup with trap
- Design for idempotency - Scripts should be safe to rerun
- Document requirements - List dependencies and minimum versions
- Test error paths - Ensure error handling works correctly
- Use
command -v- Safer thanwhichfor checking executables - Prefer printf over echo - More predictable across systems
자주 묻는 질문
'엄격 모드'란 무엇인가요?
스크립트를 더 엄격하게 만들어, 그렇지 않으면 놓칠 수 있는 흔한 오류를 반드시 고치도록 하는 규칙 세트(`set -Eeuo pipefail`)입니다.
왜 변수에 따옴표를 써야 하나요?
변수 값 안의 공백이나 특수 문자를 스크립트가 잘못 해석하지 않도록 따옴표로 감싸야 합니다. 이렇게 하면 오류를 막을 수 있습니다.
'멱등성'은 무엇을 뜻하나요?
멱등한 스크립트는 여러 번 실행해도 의도하지 않은 부작용이 생기지 않습니다. 몇 번을 실행하든 최종 결과가 같습니다.
상세 정보
작성자의 원본 설명
Master defensive Bash programming techniques for production-grade scripts. Use when writing robust shell scripts, CI/CD pipelines, or system utilities requiring fault tolerance and safety.
repo: wshobson/agents
인기도
- GitHub 스타
- 41k
- 순위
- #6783
- 라이선스
- MIT
- 업데이트
- 2026. 10. 15.
댓글
- …
이 저장소의 다른 스킬
screen-reader-testing
41k에이전트가 스크린 리더로 웹사이트를 테스트해 접근성을 확인하도록 돕습니다.
wcag-audit-patterns
41k에이전트가 WCAG 지침에 따라 웹사이트의 접근성을 감사하고 문제를 고치도록 돕습니다.
multi-reviewer-patterns
41k에이전트가 병렬 코드 리뷰를 조율하고, 중복된 발견 사항을 정리하며, 보고서를 통합하도록 돕습니다.
parallel-debugging
41k에이전트가 병렬 조사와 근본 원인 분석으로 복잡한 문제를 디버그하도록 돕습니다.