Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have tested this with both Ubuntu 12.04 and Debian 7. When I do

echo $TERM

I get

xterm

But if I use the dropdown menu "help" > "about" then it says gnome terminal 3.4.1.1.

Does this mean I am using just gnome-terminal? Or just xterm? Or is gnome-terminal an extension of xterm? I'm confused.

share|improve this question

3 Answers 3

up vote 16 down vote accepted

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 want's 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 lets 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 lets 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.

share|improve this answer
2  
Recommending someone export $TERM really seems like rubbing salt into an open wound... –  jasonwryan Oct 3 '13 at 5:16
    
yeah. i'm guessing that the developers of gnome-terminal left $TERM set to xterm for a good reason –  mulllhausen Oct 3 '13 at 13:07
    
@mulllhausen That reason is well explained in my answer... –  Patrick Aug 18 at 0:58

The 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 TERM=xterm.

To find out what terminal a shell is running it, look at the parent of the shell:

ps -p$PPID
share|improve this answer
    
Thanks - this solved it for me, that ps -p snippet. –  user722915 Nov 9 at 7:32

The environment variable TERM does not mean the terminal you are using.

Quoting gnu.org:

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

rxvt is often built with support for 16 colors. You can try to set TERM to rxvt-16color. konsole

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.