Command format: readonly variable_name
variable_name = name of the variable to be made read only
Sample Session:
$person=Kathleen
$readonly person
$echo $person
Kathleen
$person=Richard
person: is read only
$
The readonly command given without any arguments will display a
list of all the read-only variables.
Sample Session:
$person=Kathleen
$readonly person
$example=Richard
$readonly example
$readonly
readonly person
readonly example
$
Command format: expr expression
See Appendix C for a complete list of expressions
The arguments are taken as an expression. After the evaluation has
taken place, the result is written to standard output. The terms
of the expression must be separated by blanks. Special characters
to the shell must be escaped. Strings containing blanks or other
special characters must be quoted.
Sample Session:
$expr 7 + 8 + 10
25
$expr 10 - 8
2
$expr 10 '*' 4
40
$expr 135 / 5
27
$
expr will also work with user defined variables as in the following
example:
Sample Session:
$cat data
8
15
25
$cat express
count=0
tot=0
for a in `cat data`
do
tot=`expr $tot + $a`
count=`expr $count + 1`
done
avg=`expr $tot / $count`
echo "The average is $avg"
$
Let's execute the script "express" with tracing on so we can follow
the execution.
Sample Session:
$sh -x express
count=0
tot=0
+ cat data
+ expr 0 + 8
tot=8
+ expr 0 + 1
count=1
+ expr 8 + 15
tot=23
+ expr 1 + 1
count=2
+ expr 23 + 25
tot=48
+ expr 2 + 1
count=3
+ expr 48 / 3
avg=16
+ echo The average is 16
The average is 16
$