본문으로 건너뛰기
Skillpedia
일반 코딩41k · #6783

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가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/wshobson/agents/blob/main/plugins/shell-scripting/skills/bash-defensive-patterns/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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

  1. Always use strict mode - set -Eeuo pipefail
  2. Quote all variables - "$variable" prevents word splitting
  3. Use [[]] conditionals - More robust than [ ]
  4. Implement error trapping - Catch and handle errors gracefully
  5. Validate all inputs - Check file existence, permissions, formats
  6. Use functions for reusability - Prefix with meaningful names
  7. Implement structured logging - Include timestamps and levels
  8. Support dry-run mode - Allow users to preview changes
  9. Handle temporary files safely - Use mktemp, cleanup with trap
  10. Design for idempotency - Scripts should be safe to rerun
  11. Document requirements - List dependencies and minimum versions
  12. Test error paths - Ensure error handling works correctly
  13. Use command -v - Safer than which for checking executables
  14. 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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬