old-www/HOWTO/Bash-Prompt-HOWTO/c583.html

240 lines
4.6 KiB
HTML

<HTML
><HEAD
><TITLE
>Special Characters: Octal Escape Sequences</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Bash Prompt HOWTO"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="Colours and Cursor Movement With tput"
HREF="x405.html"><LINK
REL="NEXT"
TITLE="The Bash Prompt Package"
HREF="the-bash-prompt-package.html"></HEAD
><BODY
CLASS="CHAPTER"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Bash Prompt HOWTO: </TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x405.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="the-bash-prompt-package.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="AEN583"
></A
>Chapter 7. Special Characters: Octal Escape Sequences</H1
><P
>Outside of the characters that you can type on your keyboard, there are a
lot of other characters you can print on your screen. I've created a
script to allow you to check out what the font you're using has available
for you. The main command you need to use to utilize these characters is
"echo -e". The "-e" switch tells echo to enable interpretation of
backslash-escaped characters. What you see when you look at octal 200-400
will be very different with a VGA font from what you will see with a
standard Linux font. Be warned that some of these escape sequences have
odd effects on your terminal, and I haven't tried to prevent them from
doing whatever they do. The linedraw and block characters that are used
heavily by the Bashprompt project are between octal 260 and 337 in the VGA
fonts.</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
>#!/bin/bash
# Script: escgen
function usage {
echo -e "\033[1;34mescgen\033[0m &#60;lower_octal_value&#62; [&#60;higher_octal_value&#62;]"
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&#13;</PRE
></FONT
></TD
></TR
></TABLE
><P
>You can also use <B
CLASS="COMMAND"
>xfd</B
> to display all the characters in
an X font, with the command <B
CLASS="COMMAND"
>xfd -fn &#60;fontname&#62;</B
>.
Clicking on any given
character will give you lots of information about that character, including
its octal value. The script given above will be useful on the console, and
if you aren't sure of the current font name.</P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x405.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="the-bash-prompt-package.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Colours and Cursor Movement With <B
CLASS="COMMAND"
>tput</B
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>The Bash Prompt Package</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>