9

I set the $TERM variable adding the line XTerm*termName: xterm-256color to my .Xresources file. When I did it I didn't know what exactly that meant (I was following an online guide to change the look of xterm), but now I have read a little more and am concerned if what I did was wrong. Specifically I want to know there is something bad in setting the $TERM variable manually, and in case it is, how can I revert my mistake.

In case you need, I'm running Fedora 20 with xterm.

  • This is a generic programming question. Depends on what you will be doing. If you can take for granted a desktop environment and absence of remote connections, might be OK. If not, all possible cases have to be processed with error checking. – uprego Jan 8 '14 at 15:07
  • @uprego Could you please elaborate on "abscence of remote connections"? – Santaru72 Jan 8 '14 at 15:16
  • You might be using a permanent tmux session with the 256 color option, but if you attach it from a ssh session, the possible scenarios broaden too much to list. Each application would have or not desirable effects depending on each programmers ability. As @goldilocks points out in his answer should not be dangerous, but there is the difference between "should not be" and "can not be". – uprego Jan 8 '14 at 15:24
  • @uprego : Realistically, I should have said "can not", unless you count illegible output as "dangerous". – goldilocks Jan 8 '14 at 15:39
6

For the most part, you should not set TERM manually. The variable is always set automatically, and there is only a narrow set of circumstances where the default value is incorrect.

The value of TERM needs to be referenced in the system's terminfo database (or for a few old-fashioned system, in the termcap database). Terminfo and Termcap map terminal types to the description of terminal capabilities that applications use. The value of TERM is the terminal type.

The main reason why you might sometimes need to change TERM is if you log in remotely, when the local machine and the remote machine have different terminal databases.

Another reason, which is related to the previous one, is that sometimes there are multiple similar entries for a terminal, with slightly different capabilities. This tends to happen mostly when a new terminal comes up which is compatible with an existing terminal, but has more features. You then get a choice between using the traditional name, which all machines understand, but which advertises only the traditional features, or the newer name, which advertises all the new features but which some machines won't understand.

An example of this is xterm with 16 colors vs xterm with 256 colors. A traditional xterm supports only 16 colors, so that's what the xterm terminal database specifies. Changing the xterm entry would make users of the newer xterm versions happy, but would break the configuration of users of older xterm versions who log in remotely. Switching to a new name — xterm-256color — provides the newer capabilities whenever available, but is not recognized if you log in remotely to machines with an older terminal database. Because there is no solution that can satisfy everyone, you get a choice: either stick with xterm and don't get the 256 colors, or use xterm-256color which doesn't work if you log in to remote machines that don't support it.

Leaving the default value of xterm and setting the termName resource to xterm-256color (which causes the environment variable TERM to be set to the same value) are thus both sensible choices. Setting TERM to arbitrary values wouldn't work, but both xterm and xterm-256color make sense.

3

I set the $TERM variable adding the line XTerm*termName: xterm-256color to my .Xresources file.

That's fine, as long as you are aware of what you've done; most GUI terminals support this.

You can also set it from the command line or in a script

export TERM=xterm-256color

This only applies to that terminal, or subsequent children.

A portable default would be just xterm, which means 16 color support. If you have 256-color set and your terminal doesn't support it, running 256 color TUI apps will just look weird; you'll probably notice right away. But it should not be dangerous.

  • So setting XTerm*termName: xterm instead of XTerm*termName: xterm-256color I should be fine, right? – Santaru72 Jan 8 '14 at 15:46
  • If that's what you want, don't set anything; xterm is the default for xterm ;) but it means 16 colors. The major point of using xterm-256color is to tell applications that the terminal supports 256 colors. If you don't do that, they'll presume 16 colors. – goldilocks Jan 8 '14 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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