for filename in "$@"; do
case $filename in
*.c )
objname=${filename%.c}.o
ccom "$filename" "$objname" ;;
*.s )
objname=${filename%.s}.o
as "$filename" "$objname" ;;
*.o ) ;;
* )
print "error: $filename is not a source or object file."
exit 1 ;;
esac
done
The case construct in this code handles four cases. The first
two are similar to the if and first elif cases in the
code earlier in this chapter; they call the compiler or the assembler if the
filename ends in .c or .s, respectively.
After that, the code is a bit different. Recall that if the
filename ends in .o nothing is to be done (on the assumption
that the relevant files will be linked later).
We handle this with
the case *.o ), which has no statements. There is nothing
wrong with a "case" for which the script does nothing.
Let's assume that your system has ten lines plus a system
console line (/dev/console), with the following terminals:
Lines tty01, tty03, and tty04 are Givalt GL35a's
(terminfo name "gl35a").
Line tty07 is a Tsoris T-2000 ("t2000").
Line tty08 and the console are Shande 531s ("s531").
The rest are Vey VT99s ("vt99").
Here is the code that does the job:
case $(tty) in
/dev/tty0[134] ) TERM=gl35a ;;
/dev/tty07 ) TERM=t2000 ;;
/dev/tty08 | /dev/console ) TERM=s531 ;;
* ) TERM=vt99 ;;
esac
The value that case checks is the result of command substitution.
Otherwise, the only thing new about this code is the OR bar
after /dev/tty08. This means that
/dev/tty08 and /dev/console are alternate patterns for the case
that sets TERM to "s531".
Note that it is not possible
to put alternate patterns on separate lines unless you use backslash
continuation characters at the end of all but the last line.
In other words, the line:
/dev/tty08 | /dev/console ) TERM=s531 ;;
could be changed to the slightly more readable:
/dev/tty08 | \
/dev/console ) TERM=s531 ;;