← Back to list

shell-patterns
by maxbeworks
I convinced myself it will make me more productive
⭐ 0🍴 0📅 Jan 12, 2026
SKILL.md
name: shell-patterns description: Shell scripting patterns - portability, explicit error handling, readability over cleverness
Philosophy
- Shell scripts should be obvious
- Portability matters - your script will run on systems you don't control
- Explicit error handling - scripts shouldn't silently fail halfway through
Shebang and Compatibility
- Use
#!/usr/bin/env bashfor portability, not#!/bin/bash - If you need bash-specific features, use bash - don't try to make it POSIX when it's not
- For truly portable scripts, stick to POSIX sh and test on different shells
- Target systems will always be Linux by default unless explicitly told otherwise
Functions
- Use functions for repeated logic - don't copy-paste the same shit
- Name functions clearly -
backup_confignotbc - Keep functions focused - one job per function
- Return meaningful exit codes (0 for success, non-zero for failure)
Variables
- Use
"${var}"instead of$var- quote everything unless you want word splitting - UPPER_CASE for environment/global vars, lower_case for local/function vars
localkeyword for function variables - don't pollute global scope- Check if vars are set before using:
${var:-default}or explicit checks
Commands and Tools
- Never assume a non-default tool exists - ask user before
- Prefer common POSIX tools over GNU-specific extensions when possible
- Use command substitution
$(command)instead of backticks - it's more readable
Loops and Arrays
- Use
while readfor processing command output line by line - Arrays in bash:
arr=("one" "two")- but remember they're bash-specific - Loop over files safely:
for file in *.txt; do [[ -e "$file" ]] || continue - Avoid parsing
lsoutput - use globs orfindwith-print0andwhile read -d ''
Output and Logging
- Use
echofor simple output,printfwhen you need formatting - stderr for errors:
echo "Error message" >&2
Anti-Patterns
- Not quoting variables - guaranteed to break with spaces
- Parsing
lsoutput instead of using proper tools - Ignoring error codes and letting scripts continue after failures
- Using
cdwithout checking if it succeeded - Not cleaning up temporary files
Score
Total Score
50/100
Based on repository quality metrics
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
Reviews
💬
Reviews coming soon