shell-scripting
撰寫穩健的 Shell 腳本
또한 다음에서 사용할 수 있습니다: Joseph OBrien,Joseph OBrien
Shell 腳本常因未加引號的變數、缺少錯誤處理與不安全模式而失敗。此技能提供可直接上線的範本、安全意識的最佳實務,以及現代命令列替代方案,協助你撰寫可維護的 Bash 與 Zsh 腳本。
스킬 ZIP 다운로드
Claude에서 업로드
설정 → 기능 → 스킬 → 스킬 업로드로 이동
토글을 켜고 사용 시작
테스트해 보기
"shell-scripting" 사용 중입니다. Write a Bash script to process log files safely
예상 결과:
- Start with proper shebang and safe options: #!/usr/bin/env bash, set -euo pipefail
- Use null-delimited iteration: while IFS= read -r -d '' file
- Validate files before processing: [[ -f "$file" ]] || continue
- Add trap for cleanup: trap cleanup EXIT to remove temporary files
"shell-scripting" 사용 중입니다. How do I handle errors and exit codes properly in a shell script?
예상 결과:
- Use set -euo pipefail at script start to catch errors immediately
- Check exit codes explicitly: if command; then ... else ... fi
- Use ERR trap to capture line numbers: trap 'echo "Error on $LINENO"' ERR
- Create cleanup function with EXIT trap for resource cleanup
"shell-scripting" 사용 중입니다. Show me how to safely process user input in shell scripts
예상 결과:
- Always quote variables: "$variable" not $variable
- Validate input before use with pattern matching: [[ "$input" =~ ^[a-zA-Z0-9]+$ ]]
- Avoid eval with untrusted input - it enables code injection
- Use read with explicit prompts and validation
보안 감사
안전This is a pure knowledge/documentation skill containing shell scripting best practices and templates. The static scanner detected shell patterns (command substitution, backticks, external commands) but these are all in documentation examples showing how to write scripts safely. The content explicitly teaches security best practices including avoiding eval with untrusted input, using mktemp for temp files, and not storing secrets in scripts. No executable code, file access, or network operations exist - only educational examples demonstrating proper shell scripting techniques.
위험 요인
⚡ 스크립트 포함 (1)
⚙️ 외부 명령어 (2)
품질 점수
만들 수 있는 것
撰寫可維護的腳本
學習適合上線使用的安全加引號、錯誤處理與組織模式。
自動化部署任務
建立具備適當 trap 處理器與訊號管理的穩健自動化腳本。
高效管理系統
使用高效的檔案處理、程序管理與文字操作技巧。
이 프롬프트를 사용해 보세요
Show me the proper header and structure for a Bash script using best practices including set -euo pipefail.
How do I use set -euo pipefail, traps, and proper exit codes for robust error handling in shell scripts?
Write a Bash function to safely iterate through files with spaces in names using null delimiters instead of parsing ls.
Create a script template that works in both Bash and Zsh with conditional Zsh-specific features and advanced globbing.
모범 사례
- 務必為變數加上引號:"$variable" 而非 $variable,以安全處理空白與特殊字元
- 在腳本開頭使用 set -euo pipefail 以提早捕捉錯誤並防止默默失敗
- 在使用外部工具前,以 command -v 驗證命令是否存在以提升可攜性
피하기
- 不要解析 ls 輸出;改用帶有 nullglob 的 glob 或使用 find 搭配 -print0
- 避免對不受信任的輸入使用 eval;它會造成程式碼注入與安全性漏洞
- 不要使用未加引號的變數;它們會在空白處進行字詞分割並展開 glob