顯示頁面舊版反向連結Fold/unfold all回到頁頂 本頁是唯讀的,您可以看到原始碼,但不能更動它。您如果覺得它不應被鎖上,請詢問管理員。 ====== 針對 shell script 測試工具(shellcheck) ====== * 因為最近用 AI 協助撰寫不少 shell script , 愈寫愈複雜, 想想應該要找個測試工具來幫忙 * 以下是使用 shellcheck 的方式 ===== 安裝方式 ===== * Ubuntu / Debian <cli> sudo apt install shellcheck </cli> ===== 建議測試原則 ===== * 只修正 critical 項目 <cli> shellcheck -S error scripts/*.sh </cli> * 範例: * 全部列出 <cli> jonathan@200816-NB:~/github/docker-compose$ shellcheck scripts/*.sh In scripts/alpine_upgrade.sh line 23: echo -e "${BLUE}[INFO]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" ^-- SC3037 (warning): In POSIX sh, echo flags are undefined. In scripts/alpine_upgrade.sh line 27: echo -e "${GREEN}[SUCCESS]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" ^-- SC3037 (warning): In POSIX sh, echo flags are undefined. In scripts/alpine_upgrade.sh line 31: echo -e "${YELLOW}[WARNING]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" ^-- SC3037 (warning): In POSIX sh, echo flags are undefined. In scripts/alpine_upgrade.sh line 35: echo -e "${RED}[ERROR]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1" ^-- SC3037 (warning): In POSIX sh, echo flags are undefined. In scripts/alpine_upgrade.sh line 51: trap cleanup_on_error ERR ^-^ SC3047 (warning): In POSIX sh, trapping ERR is undefined. : </cli> * 只看 error <cli> jonathan@200816-NB:~/github/docker-compose$ shellcheck -S error scripts/*.sh jonathan@200816-NB:~/github/docker-compose$ </cli> {{tag>bash}} tech/shellcheck.txt 上一次變更: 2025/10/07 11:59由 jonathan