記錄一下shell日誌顏色處理 ...
記錄一下shell日誌顏色處理
_COLORS=${BS_COLORS:-$(tput colors 2>/dev/null || echo 0)} __detect_color_support() { # shellcheck disable=SC2181 if [ $? -eq 0 ] && [ "$_COLORS" -gt 2 ]; then RC='\033[1;31m' GC='\033[1;32m' BC='\033[1;34m' YC='\033[1;33m' EC='\033[0m' else RC="" GC="" BC="" YC="" EC="" fi } __detect_color_support echoerror() { printf "${RC} * ERROR${EC}: %s\\n" "$@" 1>&2; } echoinfo() { printf "${GC} * INFO${EC}: %s\\n" "$@"; } echowarn() { printf "${YC} * WARN${EC}: %s\\n" "$@"; }