Testing for color support in Linux shell scripts
You can use tput colors
.
For my terminal with TERM=xterm-256colors
the output is [drumroll] 256! Here are some other examples:
$ TERM=vt100 tput colors-1$ TERM=vt220 tput colors-1$ TERM=linux tput colors8$ TERM=cons25 tput colors8$ TERM=linux tput colors8$ TERM=rxvt-unicode tput colors88
Alternatively tput -Tvt100 colors
will also allow you to specify the terminal type you're interested in.