I write:

  $ infocmp -1 xterm
        ...
    colors#8,
    bold=\E[1m,
    blink=\E[5m,
        ...
  $ tput -Txterm colors && echo OK || echo err
8
OK
  $ tput -Txterm blink && echo OK || echo err
^[[5mOK

So I can use tput to check retminal capabilities.

Is this soution portable? Are there any another solutions?

Or may be I can stuck with solution:

  $ [ $TERM = xterm ] && echo ok || echo err
ok

One use is to set PS1 in .bashrc. Another for highliting output to take attention from sh script. I can use such solution:

PS1='bash# '
case "$TERM" in
  xterm*) PS1='\[\033[35m\]bash# \[\033[0m\]'
  ;;
esac

which uses only built-in command of bash (so efficient) and work for all my cases but unfortunately does not portable.

link|improve this question

43% accept rate
feedback

1 Answer

up vote 1 down vote accepted

Using tput is portable to a large number of operating systems.

However checking the return code only tells you whether the platform's terminfo database has a definition of that capability in it's entry for 'xterm'.

The return code does not tell you whether the currently used 'xterm' client actually supports that capability.

Note that there are a great variety of software programs that claim to be 'xterm' compatible. It is certainly likely that not all of them support all 'xterm' features, especially considering that there have been several consecutive versions of the reference implementation of xterm released and probably some forks. The xterm maintainer says "None implements as many as half of xterm's controls."

So far as I know, none of the usual standards bodies (ANSI, ECMA, The Open Group) have published a standard that defines xterm. The current maintainer of xterm does also maintain a vt100 test program (vttest) to assist with his xterm work.

So, there's probably no way an application itself can make use of the TERM value to be sure that a terminal claimed to be an xterm actually supports a specific xterm feature. At least not for any arbitrary choice of xterm feature. If you involve a human (as I recall vttest did) you may have a better chance.

link|improve this answer
OK. Terminals can not say about its capabilities so $TERM ~= xterm* heuristics is pretty good. – gavenkoa Sep 7 '11 at 23:08
feedback

Your Answer

 
or
required, but never shown

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