Glam Prestige Journal

Bright entertainment trends with youth appeal.

I recently upgraded (with apt-get dist-upgrade) my Kubuntu and Lubuntu Linux boxes, and now every time I log into one of these machines, I get this message:

tput: No value for $TERM and no -T specified

Here is a screenshot of the exact message:tput: No value for $TERM and no -T specified

This happened on both my Lubuntu machine and Kubuntu machine, and it wasn't a problem until after I upgraded; so I suspect that it was not user error.

How can I fix this?

UPDATE

I have tracked this down to my .bashrc file, which is getting called by my .profile file. Though, the fact that my .bashrc file now runs when I do a GUI login whereas it didn't before I upgraded is a bit weird. And no, I haven't modified my .bashrc file or my .profile recently. Also, bash isn't my default shell.

The problem is that I am calling tput in my .bashrc file to set up variables for use in adding color to the prompt. But at the (inappropriate) time when my .bashrc file now gets run, $TERM is not set.

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)

Updated question: How should I fix this? Should I set $TERM myself? Or should I just not set these variables if $TERM is not set?

UPDATE 2

One solution I tried was to check whether $TERM was set. But this didn't seem to work; I still got the same error message. Here's the code:

if [ ! "$TERM" = "" ]; then #Do stuff here
fi

So apparently $TERM was set, but tput still concluded it wasn't.

3

7 Answers

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
5

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"

1

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

0

[Different scenario, but search engine lead me here first]

When "tput: No value for $TERM and no -T specified" error occurs in a Docker container (for me, when opening a zsh shell calling docker exec -it <container> zsh (-i for interactive)) the only way to fix this, was to set the variable like ENV TERM xterm-256color in the Dockerfile for this image.

Approaches like RUN export TERM=xterm-256color or RUN echo "export TERM=xterm-256color" >> ~/.zshrc were not successful. Other values for TERM are also possible.

Try opening terminal (doesn't matter which, even tty1 will do) and run this line

sudo update-alternatives --config x-terminal-emulator

You will be presented with choice of the default terminal emulator for x window. Choose one by selecting number, and reboot after you're done.

$ sudo update-alternatives --config x-terminal-emulator
There are 6 choices for the alternative x-terminal-emulator (providing /usr/bin/x-terminal-emulator).

 Selection Path Priority Status
------------------------------------------------------------ 0 /usr/bin/gnome-terminal.wrapper 40 auto mode 1 /usr/bin/gnome-terminal.wrapper 40 manual mode 2 /usr/bin/koi8rxterm 20 manual mode
* 3 /usr/bin/lxterm 30 manual mode 4 /usr/bin/sakura 40 manual mode 5 /usr/bin/uxterm 20 manual mode 6 /usr/bin/xterm 20 manual mode
Press enter to keep the current choice[*], or type selection number: 
5

The error dialog is due to the fix of bug #678421, so it's my fault. ;) It tells you about errors due to some command(s) in one of your configuration files. If you scroll to the top, you can see which file is causing the error messages.

Possibly Serg's answer is sufficient to get rid of the warning dialog.

Edit:

Would like to add a couple of things due to the updated question.

Unlike before, /usr/sbin/lightdm-session is now run under bash (previously sh). That's why its sourcing of ~/.profile results in ~/.profile sourcing ~/.bashrc. Possibly this means that the default contents of ~/.profile ought to be changed.

The easiest thing you can do to fix it is, as you suggested, to only call tput if $TERM is set.

4

--> MY WORKING SOLUTION FOR THE TPUT-PROBLEM:


# when $TERM is empty (non-interactive shell), then expand tput with '-T xterm-256color'
[[ ${TERM}=="" ]] && TPUTTERM='-T xterm-256color' \ || TPUTTERM=''
declare -r RES='tput${TPUTTERM} sgr0' REV='tput${TPUTTERM} rev'
declare -r fRD='tput${TPUTTERM} setaf 1' bRD='tput${TPUTTERM} setab 1'
declare -r fGN='tput${TPUTTERM} setaf 2' bGN='tput${TPUTTERM} setab 2'
...
echo ${fRD}" RED Message: ${REV} This message is RED REVERSE. "${RES}
echo ${fGN}" GREEN Message: ${REV} This message is GREEN REVERSE. "${RES}
... 

That way the tput command is still working as fine as possible and
it makes no sense if it is an interactive or non-interactive shell...

6a5h4

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