Understanding $TERM
2月 25, 2024
·
1 分钟阅读时长
·
157
字
·
-阅读
-评论
While building a WebShell I kept seeing scripts reference
$TERM. Here’s a quick primer on what it does and why it matters.

What Is $TERM?
$TERMis 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:
xtermxterm-colorxterm-256colorvt220vt100dumblinux
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
- You can set
$TERMin shell startup files (~/.bashrc,~/.bash_profile, etc.). - SSH clients set it when opening sessions. For instance, the
ssh2client 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.

