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.
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
- You can set
$TERM
in shell startup files (~/.bashrc
,~/.bash_profile
, etc.). - 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.