Could someone explain this? I'm using gnome-terminal. First, some information:# echo $TERMxterm# infocmp xtermReconstructed via infocmp from file: /lib/terminfo/x/xtermcolors#8, cols#80, it#8, lines#24, pairs#64# tput colors8I wrote simple script to create codes for extended set of colors:# Output file (current directory) and text.OFILE='xterm256_colors_test.sh'OFILE_COLORS='terminal_256_colors'OTEXT='Sed ut perspiciatis unde omnis iste natus error sit voluptatem...'# Clearing the contents from previous runs.if [ -e $OFILE ] || [ -e $OFILE_COLORS ]then  > $OFILE  > $OFILE_COLORSfi# Bang!echo -e '#!/bin/bash\n' | tee --append $OFILE $OFILE_COLORS &> /dev/nullecho -e \necho -e \ | tee --append $OFILE &> /dev/null# \x1b is a control character changing behaviour of the shell.# It is also the <Ctrl+V><Esc> sequence.for i in {016..255}; do  echo -e \x1b[38;5;${i}m $OTEXT $i \x1b[0m >> $OFILE  echo -e color${i}=\\[\033[38;5;${i}m\]\ >> $OFILE_COLORSdone# End of echo.echo '' | tee --append $OFILE &> /dev/null# The file should be executable.chmod +x $OFILEDespite the basic xterm terminal emulator when I run the generated script I can see all 240 colors. Why? I thought I should change $TERM to xterm-256color first.
Why xterm displays 256 colors (not xterm-256color)?
gnome terminal;xterm
The TERM environment variable is a way that you, the user,can tell programs (e.g., emacs, grep, less, ls, and vim)what kind of terminal they are running on, so they will know its parameters, including what capabilities it has and what escape sequences they need to issue to access them. This exists because its too hard, in general,for the software to determine this for itself(and was prettymuch impossible when users interfacedwith computers through terminals that were external,and only connected to the computer by a data cable).gnome-terminal is a program that provides terminal-like servicesto the user and the programs thatthe user runs within the terminal.gnome-terminal may be aware of environment variablesthat were set in its environment,before it was invoked (DISPLAY being the obvious example),but it has no knowledge of environment variables that are setin in the processes that are running under it.So, gnome-terminal has whatever capabilities it has.It may be possible to adjust/constrain these externally,e.g., through command-line options, the pre-existing environment,configuration files, and dialogs in the window frame,but not by changing TERM in the shell in the window.If its capable of displaying 256 colors,then its capable of displaying 256 colors,and you will be able to cause it to do soby sending it the appropriate escape sequences.But, as long as you have TERM set to xterm,the programs that you run will believe that you are telling themthat they are running in an eight-color-capable terminal,and so they will restrict their requests (escape sequences)to those capabilities.You need to set TERM to xterm-256color,not to enable gnome-terminal to display 256 colors,but totell programs like grep and ls to ask itto use more than 8 colors.