What is $TERM
for?
The $TERM
variable is for use by applications to take advantage of capabilities of that terminal.
For example, if a program wants to display colored text, it must first find out if the terminal you're using supports colored text, and then if it does, how to do colored text.
The way this works is that the system keeps a library of known terminals and their capabilities. On most systems this is in /usr/share/terminfo
(there's also termcap, but it's legacy not used much any more).
So let's say you have a program that wants to display red text. It basically makes a call to the terminfo library that says "give me the sequence of bytes I have to send for red text for the xterm terminal". Then it just takes those bytes and prints them out.
You can try this yourself by doing tput setf 4; echo hi
. This will get the setf
terminfo capability and pass it a parameter of 4
, which is the color you want.
Why gnome terminal lies about itself:
Now let's say you have some shiny new terminal emulator that was just released, and the system's terminfo library doesn't have a definition for it yet. When your application goes to look up how to do something, it will fail because the terminal isn't known.
The way your terminal gets around this is by lying about who it is. So your gnome terminal is saying "I'm xterm".
Xterm is a very basic terminal that has been around since the dawn of X11, and thus most terminal emulators support what it supports. So by gnome terminal saying it's an xterm, it's more likely to have a definition in the terminfo library.
The downside to lying about your terminal type is that the terminal might actually support a lot more than xterm does (for example, many new terminals support 256 colors, while older terminals only supported 16). So you have a tradeoff, get more features, or have more compatibility. Most terminals will opt for more compatibility, and thus choose to advertise themselves as xterm
.
If you want to override this, many terminals will offer some way of configuring the behavior. But you can also just do export TERM=gnome-terminal
.
$TERM
set toxterm
for a good reason – mulllhausen Oct 03 '13 at 13:07