More on shells
Overview
Simple arithmetic
Arithmetic
expansion
Operators for arithmetic
expansion
The 'expr'
command
Pattern matching
Patterns
Examples of patterns
The case
statement
Entering and leaving the
shell
More about scripts with
options
Symbolic
links
Setting up terminals
Conventions used in
UNIX file systems
Summary
Exercises
|
Setting up terminals
With a bit of luck, you'll never have to worry about the
'characteristics' of your own terminal, but it is possible that you
may have to hook up a terminal to the system and then find it's not
quite in order. The command tput is provided to help
you check basic characteristics of your terminal, using knowledge
provided by the environment variable TERM . It can
perform operations such as 'resetting' or 'initialising' your
terminal (if either is possible) and cause your screen to 'clear'.
The usability of this command depends entirely on the type of
terminal you are using, and only three actions are specified by
POSIX. To clear the terminal screen, invoke tput with
argument clear :
$ tput clear
The reset and initialise procedures require arguments
reset and init respectively, and their
actions depend on the system you are using. Typically you may need
tput reset if your terminal starts to respond
unexpectedly, which is sometimes due to having received spurious
data it has interpreted. This can sometimes happen if you
cat a binary file by mistake. Check the manual page
for tput to find out precisely what effect binary
files will have on your system. The TAB key provides a
TAB character as input to the system. For most purposes a
TAB can be treated as a Space, and both are
sometimes collectively described as whitespace.
The effect of touching a TAB key is to move the cursor to
the next tab position. You can reset the tab
positions on your terminal (just for the duration of your current
session) using the command tabs . Followed by a
comma-separated list of numbers, tabs will reset the
tab positions to those column numbers. So, to set the tab positions
to columns 5, 10 and 15, you would type:
$ tabs 5,10,15
Note that the tabs command only works on some
terminals.
Tabs are useful in text files if you want to line up columns,
and don't wish to involve yourself in any complex text formatting
programs. It is a good idea when writing shell scripts to 'line up'
the first character of each command to clearly identify commands
inside a loop. For instance, in the following script, the 'body' of
the for loop is made up of two commands that have been
indented by several spaces.
for i in *
do
printf "File %s has size " $i
wc -c $i
printf "\n"
done
Rather than count the number of spaces each time, you may find
it easier to insert a TAB character instead:
for i in *
do
TABprintf "File %s has size " $i
TABwc -c $i
TABprintf "\n"
done
|