$TERM Explained (Simple Guide)

Explains the $TERM environment variable, common values, and how it affects terminal capabilities.

Feb 25, 2024 · 1 min read · 157 Words · -Views -Comments · Programming
WebShell 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

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