第 7 章。特殊字符:八进制转义序列

除了您可以在键盘上输入的字符之外,还有许多其他字符可以在屏幕上打印出来。我创建了一个脚本,让您可以查看您正在使用的字体为您提供了哪些字符。您需要使用的主要命令是 "echo -e"。" -e" 开关告诉 echo 启用对反斜杠转义字符的解释。当您查看八进制 200-400 时,使用 VGA 字体看到的内容将与使用标准 Linux 字体看到的内容大不相同。请注意,其中一些转义序列对您的终端有奇怪的影响,我并没有试图阻止它们做任何它们所做的事情。Bashprompt 项目大量使用的 linedraw 和 block 字符在 VGA 字体中位于八进制 260 到 337 之间。

#!/bin/bash

#   Script: escgen

function usage {
   echo -e "\033[1;34mescgen\033[0m <lower_octal_value> [<higher_octal_value>]"
   echo "   Octal escape sequence generator: print all octal escape sequences"
   echo "   between the lower value and the upper value.  If a second value"
   echo "   isn't supplied, print eight characters."
   echo "   1998 - Giles Orr, no warranty."
   exit 1
}

if [ "$#" -eq "0" ]
then
   echo -e "\033[1;31mPlease supply one or two values.\033[0m"
   usage
fi
let lower_val=${1}
if [ "$#" -eq "1" ]
then
   #   If they don't supply a closing value, give them eight characters.
   upper_val=$(echo -e "obase=8 \n ibase=8 \n $lower_val+10 \n quit" | bc)
else
   let upper_val=${2}
fi
if [ "$#" -gt "2" ]
then 
   echo -e "\033[1;31mPlease supply two values.\033[0m"
   echo
   usage
fi
if [ "${lower_val}" -gt "${upper_val}" ]
then
   echo -e "\033[1;31m${lower_val} is larger than ${upper_val}."
   echo
   usage
fi
if [ "${upper_val}" -gt "777" ]
   then
   echo -e "\033[1;31mValues cannot exceed 777.\033[0m"
   echo
   usage
fi

let i=$lower_val
let line_count=1
let limit=$upper_val
while [ "$i" -lt "$limit" ]
do
   octal_escape="\\$i"
   echo -en "$i:'$octal_escape' "
   if [ "$line_count" -gt "7" ]
   then 
      echo
      #   Put a hard return in.
      let line_count=0
   fi
   let i=$(echo -e "obase=8 \n ibase=8 \n $i+1 \n quit" | bc)
   let line_count=$line_count+1
done
echo

您还可以使用 xfd 来显示 X 字体中的所有字符,命令是 xfd -fn <fontname>。单击任何给定字符将为您提供有关该字符的大量信息,包括其八进制值。上面给出的脚本在控制台上很有用,如果您不确定当前的字体名称,它也很有用。