Understanding $TERM

· 1 min read · 157 Words · -Views -Comments

While building a WebShell I kept seeing scripts reference $TERM. Here’s a quick primer on what it does and why it matters.

https://static.1991421.cn/2024/2024-02-25-225930.jpeg

What Is $TERM?

$TERM is an environment variable in Unix-like shells that defines the terminal type. It tells programs what capabilities (colors, cursor control, etc.) to expect.

Common values include:

  • xterm
  • xterm-color
  • xterm-256color
  • vt220
  • vt100
  • dumb
  • linux

Interactive SSH sessions usually report xterm-256color; non-interactive sessions often report dumb or nothing at all, which is why those sessions lack color.

Setting the Value

  1. You can set $TERM in shell startup files (~/.bashrc, ~/.bash_profile, etc.).
  2. SSH clients set it when opening sessions. For instance, the ssh2 client library lets you configure pseudo-TTY settings.

Quick Test

On Ubuntu, changing $TERM in .bashrc to vt100 removes color; xterm-256color restores it.

Takeaway

You usually don’t need to set $TERM manually—terminal emulators handle it. But now you know what it does if you ever need to override it.

References

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover