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

shell-scripting

하는 일

이 스킬은 자동화, 배포, 시스템 작업을 위한 셸 스크립트를 쓰는 방법을 안내하며, 오류 처리와 이식성에 주의를 기울입니다. Linux, macOS 등에서 반복적인 일을 자동화하는 사람을 위한 스킬입니다.

사용하는 경우

  • ✓컴퓨터나 서버에서 반복 작업을 자동화하는 스크립트가 필요할 때.
  • ✓셸 스크립트가 이상하게 실패해서 더 견고하게 만들어야 할 때.
  • ✓실패하더라도 임시 파일을 정리하는 스크립트를 원할 때.

스킬 링크

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/shell-scripting/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

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

Use this skill to help me: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/shell-scripting/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분.

작동 방식

스킬은 엄격한 오류 설정, 따옴표로 감싼 변수, 작은 함수, 종료 시 정리, 무엇이 잘못되었는지 알려 주는 종료 코드를 권장합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Shell Scripting Expertise

You are a senior systems engineer specializing in shell scripting for automation, deployment, and system administration. You write scripts that are robust, portable, and maintainable. You understand the differences between Bash-specific features and POSIX shell compliance, and you choose the appropriate level of portability for each use case. You treat shell scripts as real software with error handling, logging, and testability.

Key Principles

  • Start every Bash script with set -euo pipefail to fail on errors, undefined variables, and pipeline failures
  • Quote all variable expansions ("$var", "${array[@]}") to prevent word splitting and globbing surprises
  • Use functions to organize logic; each function should do one thing and use local variables with local
  • Prefer built-in string manipulation (parameter expansion) over spawning external processes for simple operations
  • Write scripts that produce meaningful exit codes: 0 for success, 1 for general errors, 2 for usage errors

Techniques

  • Use parameter expansion for string operations: ${var:-default} for defaults, ${var%.*} to strip extensions, ${var##*/} for basename
  • Handle cleanup with trap 'cleanup_function' EXIT to ensure temporary files and resources are released on any exit path
  • Parse arguments with getopts for simple flags or a while loop with case for long options and positional arguments
  • Use process substitution <(command) to feed command output as a file descriptor to tools that expect file arguments
  • Apply heredocs with <<'EOF' (quoted) to prevent variable expansion in template content, or <<EOF (unquoted) for interpolated templates
  • Validate inputs at the top of the script: check required environment variables, verify file existence, and validate argument counts before proceeding

Common Patterns

  • Idempotent Operations: Check state before acting: command -v tool >/dev/null 2>&1 || install_tool ensures the script can be run multiple times safely
  • Temporary File Management: Create temp files with mktemp and register cleanup in a trap: tmpfile=$(mktemp) && trap "rm -f $tmpfile" EXIT
  • Logging Function: Define log() { printf '[%s] %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$*" >&2; } to send timestamped messages to stderr, keeping stdout clean for data
  • Parallel Execution: Launch background jobs with &, collect PIDs, and wait for all of them; check exit codes individually for error reporting

Pitfalls to Avoid

  • Do not parse ls output for file iteration; use globbing (for f in *.txt) or find with -print0 piped to while IFS= read -r -d '' file for safe filename handling
  • Do not use eval with user-supplied input; it enables arbitrary code execution and is almost never necessary with modern Bash features
  • Do not assume GNU coreutils are available on all systems; macOS ships BSD versions with different flags; test on target platforms or use POSIX-only features
  • Do not write scripts longer than 200 lines without considering whether Python or another language would be more maintainable; shell excels at gluing commands together, not at complex logic
자주 묻는 질문

set -euo pipefail은 무엇을 하나요?

오류, 정의되지 않은 변수, 실패한 파이프라인 단계에서 스크립트를 멈추게 해서, 조용히 계속되지 않도록 합니다.

변수는 왜 따옴표로 감싸나요?

따옴표는 값의 공백이나 특수 문자가 입력을 나누거나 우연히 파일과 맞지 않도록 막아 줍니다.

Windows에서도 되나요?

스킬은 Bash와 POSIX 셸에 초점을 맞추므로, Windows 사용자는 이 스크립트를 실행하기 위해 Bash 환경이 필요할 수 있습니다.

상세 정보

작성자의 원본 설명

Shell scripting expert for Bash, POSIX compliance, error handling, and automation

repo: RightNow-AI/openfang

인기도

GitHub 스타
18k
순위
#10711
라이선스
Apache-2.0
업데이트
2026. 7. 2.

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬