No value for $TERM and no -T specified Ubuntu LTS 18.04

I edited my .bashrc and .bash_profile files in the home directory for both the user and root. Everything works perfectly. About a week later, upon reboot I get this error, but everything still works perfectly:
"TPUT: No value for $TERM and no -T specified.
TPUT: No value for $TERM and no -T specified.
TPUT: No value for $TERM and no -T specified.
TPUT: No value for $TERM and no -T specified.
TPUT: No value for $TERM and no -T specified.
TPUT: No value for $TERM and no -T specified.
TPUT: No value for $TERM and no -T specified.
TPUT: No value for $TERM and no -T specified. As a result the profile will not be configured correctly, please fix the problem as soon as feasible."

As you can see, I have the error 8 times, which is exactly the amount of lines I used to define my PS1 variable; and each line has tput in it. How do I fix this, and what is it? My terminal's profile works perfectly.
PS: this is not a duplicate, because I did not do anything such as running windows apps, kernel/OS tweaks, or ssh.

2 Answers

Your error messages essentially tell you that the $TERM variable is not defined. Most likely something happened that caused your shell to get an environment where this variable is not set anymore: OS/terminal/sshd update, different terminal, etc. If you didn't explicitly define $TERM in one of your customized shell startup files then it must have been defined elsewhere, and an update might have removed/broken that definition. There are many variables at play here, it's not possible to pinpoint the actual reason without digging a little deeper.

The solution, however, could be relatively simple: just define $TERM in your .bash_profile or /etc/profile and set it to something meaningful, e.g.:

export TERM=screen-256color

This should work on most modern Linux distros, definitely on Ubintu.

I found the answer, but thanks for the help!

The problem was that my .bashrc file uses tput to set PS1's color. But sometimes, the .bashrc file is executed outside of a terminal environment, where there is no PS1 variable. The solution was simple: I put an if statement in my .bashrc file so that my PS1 variable is only changed if .bashrc is executed in a terminal environment.

 if [[ $- == *i* ]]
then PS1="\[$(tput setaf 252)\][user]"

PS: I found this in another answer, but I can no longer find it.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like