Gnome-Terminal reports $TERM to be `xterm`

On a clean install of Ubuntu 12.10, the default gnome-terminal is reporting $TERM to be xterm where it should really be reporting xterm-256color. What is the best way of changing this? I'm avoiding putting this in my .bashrc as that's just asking for trouble.


You were well advised not to change your startup scripts, specially ~/.bashrc. Any "terminal detection" using current $TERM or $COLORTERM in ~/.profile is merely a guess, and may, as you said, cause trouble when using other terminals (say, Putty or xterm). The terminal emulator is supposed to set $TERM, and this should not be changed from within the shell.

Gnome terminal, AFAIK, does not offer a configuration to change its TERM, but it does allow you to change your startup command, and that's all you need. Here is the trick:

Profile Preferences => Title and Command => Run a custom command instead of my shell

Then use the following command:

env TERM=xterm-256color /bin/bash

Just replace /bin/bash with your preferred shell if it's different. And no, you can't use "$SHELL" in that line for shell auto-detection ;) You have to hard-code it


For connecting with a terminal that's not able to do 256 colors.

It'd be far better to detect the terminal specifically with $COLORTERM. Look for gnome-terminal, xfce4-terminal, etc, and then set the $TERM variable to xterm-256color.

I do it with:

if [ "$COLORTERM" = "gnome-terminal" ] || [ "$COLORTERM" = "xfce4-terminal" ]
then
    export TERM=xterm-256color
elif [ "$COLORTERM" = "rxvt-xpm" ]
then
    export TERM=rxvt-256color
fi