有人可以解释一下吗?我正在使用gnome-terminal
。首先,一些信息:
# echo $TERM
xterm
# infocmp xterm
Reconstructed via infocmp from file: /lib/terminfo/x/xterm
colors#8, cols#80, it#8, lines#24, pairs#64
# tput colors
8
我编写了简单的脚本来为扩展的颜色集创建代码:
# 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_COLORS
fi
# Bang!
echo -e '#!/bin/bash\n' | tee --append $OFILE $OFILE_COLORS &> /dev/null
echo -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_COLORS
done
# End of echo.
echo '"' | tee --append $OFILE &> /dev/null
# The file should be executable.
chmod +x $OFILE
尽管有基本的xterm
终端仿真器,但运行生成的脚本时仍可以看到全部240种颜色。为什么?我想我应该改变$TERM
到xterm-256color
第一位。