From 5fb2c4624e18415823ba7dfa80713c8073e6fd25 Mon Sep 17 00:00:00 2001 From: Zhineng Li Date: Wed, 6 May 2026 11:08:20 +0800 Subject: make color setup safe in non-interactive environments When run by cron, TERM may be unset, which causes tput to fail with: tput: No value for $TERM and no -T specified Initialize color variables to empty strings by default, then apply tput-based colors only when terminal capabilities are available. This prevents startup failure in non-interactive runs while preserving colored output in interactive shells. --- iptv.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'iptv.sh') diff --git a/iptv.sh b/iptv.sh index e702a55..78e1484 100755 --- a/iptv.sh +++ b/iptv.sh @@ -5,9 +5,15 @@ set -euo pipefail CURL_ARGS=(--silent --max-time 6) # Color definitions -COLOR_DANGER=$(tput setaf 1) -COLOR_SUCCESS=$(tput setaf 2) -COLOR_RESET=$(tput sgr0) +COLOR_DANGER='' +COLOR_SUCCESS='' +COLOR_RESET='' + +if [[ -n "${TERM-}" ]] && command -v tput &>/dev/null && tput sgr0 &>/dev/null; then + COLOR_DANGER=$(tput setaf 1) + COLOR_SUCCESS=$(tput setaf 2) + COLOR_RESET=$(tput sgr0) +fi show_usage () { echo "Usage: $0 [COMMAND] [OPTIONS]" -- cgit v1.2.3