No value for $TERM and no -T specified
Solution 1:
What ultimately worked for me was to check whether the shell was an interactive shell. I based the solution on this other post at unix.stackexchange: How to check if a shell is login/interactive/batch.
So the code for the solution was:
if [[ $- == *i* ]]; then
fgRed=$(tput setaf 1) ; fgGreen=$(tput setaf 2) ; fgBlue=$(tput setaf 4)
fgMagenta=$(tput setaf 5) ; fgYellow=$(tput setaf 3) ; fgCyan=$(tput setaf 6)
fgWhite=$(tput setaf 7) ; fgBlack=$(tput setaf 0)
bgRed=$(tput setab 1) ; bgGreen=$(tput setab 2) ; bgBlue=$(tput setab 4)
bgMagenta=$(tput setab 5) ; bgYellow=$(tput setab 3) ; bgCyan=$(tput setab 6)
bgWhite=$(tput setab 7) ; bgBlack=$(tput setab 0)
fi
Solution 2:
If you do this
if tty -s
then
: # your tput commands
fi
It will fix your problem. Without the -s option tty will either display your tty or write "not a tty"
Solution 3:
For me, adding
export TERM=xterm
to /etc/profile
was the only thing that solved the problem. Actually, the error gave us a hint: No value for $TERM