I have tested this with both Ubuntu 12.04 and Debian 7. When I do
But if I use the dropdown menu “help” > “about” then it says
gnome terminal 188.8.131.52.
Does this mean I am using just gnome-terminal? Or just xterm? Or is gnome-terminal an extension of xterm? I’m confused.
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
$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
If you want to override this, many terminals will offer some way of configuring the behavior. But you can also just do
TERM environment variable indicates the terminal type, not the terminal application.
TERM has a specific purpose: it tells applications running in that terminal how to interact with the terminal.
Applications interact with terminals by writing escape sequences — sequences of characters that include nonprintable characters and have effects such as moving the cursor, erasing part of the screen, changing the current color, etc. In the old days, different brands of physical terminals had different sets of escape sequences. Therefore the operating system maintains a database of terminal types and their characteristics. The traditional database is termcap (“TERMinal CAPabilities”); many modern systems and applications have switched to terminfo. Both databases are indexed by the name of the terminal type, and applications query them using the terminal type name from the
TERM environment variables.
Nowadays, most terminals use a standard set of escape sequences with a few common sets of extensions, so you won’t see many different values of
TERM. Most GUI terminal emulators are compatible with xterm, the traditional X terminal (which is still used and maintained).
Terminal emulators that differ from xterm may add their own entry to the terminal database under their own name. However this doesn’t mesh well with remote shells. A program running on machine A but which is displaying on machine B, for example because it was launched through ssh from B to A, needs to query the terminal database on machine A. Remote login methods such as ssh carry over the
TERM environment variable, but this is helpful only when B’s terminal database also has an entry for the value user on A. Therefore many terminal emulators stick to
TERM=xterm which is pretty much universally known.
The differentiation between terminals by and large does not come from the way applications interact with them, but by the way the terminals interact with the user and fit in their environment. For example, Gnome Terminal looks good on Gnome and provides tabs and other niceties; Konsole looks good on KDE and provides tabs and other niceties; urxvt has a small memory requirement; Console2 runs on Windows; screen and tmux provide sessions that can be attached to different parent terminals; and so on. Since none of these features make a difference to applications running in the terminal, most terminal emulators use
To find out what terminal a shell is running it, look at the parent of the shell:
The environment variable TERM does not mean the terminal you are using.
The environment variable TERM contains a identifier for the text window’s
capabilities. You can get a detailed list of these cababilities by using the > ‘infocmp’ command, using ‘man 5 terminfo’ as a reference.
When producing text with embedded color directives, msgcat looks at the TERM variable. Text windows today typically support at least 8 colors. Often, however, the text window supports 16 or more colors, even though the TERM variable is set to a identifier denoting only 8 supported colors. It can be worth setting the TERM variable to a different value in these cases:
xterm is in most cases built with support for 16 colors. It can also be built with support for 88 or 256 colors (but not both). You can try to set TERM to either xterm-16color, xterm-88color, or xterm-256color.
rxvt is often built with support for 16 colors. You can try to set TERM to rxvt-16color.
konsole too is often built with support for 16 colors. You can try to set TERM to konsole-16color or xterm-16color.
After setting TERM, you can verify it by invoking ‘msgcat –color=test’ and seeing whether the output looks like a reasonable color map.
The environment variable TERM contains a identifier for the text window’s capabilities. You can get a detailed list of these cababilities by using the ‘infocmp’ command, using ‘man 5 terminfo’ as a reference.
I think it’s worth noting that you can find out the answer to your initial question by running
ps -p $$, i.e. learn what is the process with the current pid. Sample output is:
PID TTY TIME CMD 3045221 pts/17 00:00:00 bash
which is quite clear about what terminal it is.