diff options
| author | Zhineng Li <im@zhineng.li> | 2026-05-06 11:08:20 +0800 |
|---|---|---|
| committer | Zhineng Li <im@zhineng.li> | 2026-05-06 11:08:20 +0800 |
| commit | 5fb2c4624e18415823ba7dfa80713c8073e6fd25 (patch) | |
| tree | 9756cae193a5dc44b4ef95c8e16e996797293144 /iptv.sh | |
| parent | c51c5cd43305b1a2291422ce2d804b193ee941a0 (diff) | |
| download | china-unicom-iptv-gd-5fb2c4624e18415823ba7dfa80713c8073e6fd25.tar.gz china-unicom-iptv-gd-5fb2c4624e18415823ba7dfa80713c8073e6fd25.zip | |
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.
Diffstat (limited to 'iptv.sh')
| -rwxr-xr-x | iptv.sh | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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]" |
