let 修改变量值
example:$x=100
$let x=x+1 (无空格)
$echo $x
101
expr 整数运算
example:$x=10
$x='expr $x + 1' (运算符两边加空格)结果 11
set 给位置变量赋值
example: $set One Two Three
$echo $1 $2 $3
One Two Three
text 比较运算符(两边加空格)
text number1 数值比较运算符 number2
-eq 是否=
-ne !=
-gt >
-ge >=
-lt <
-le <=
test expression1 逻辑运算符 expression2
-a逻辑与
-o逻辑或
-!逻辑非
read 读键盘变量值,第i个值赋给第i个变量
例子 :求输入数组的最大值与和
#! /bn/sh
# display the summary and the largest of arguments
#
sum=0
largest=$1
for i in $*
do
sum=`expr $sum + $i`
if test $largest -lt $i
then
echo "$i"
largest=$i
else echo "$largest"
fi
done
echo "The sum = $sum"
echo "The largest is $largest"
exit 0
运行 sh SUM 29 47 23