read [parameter] [variable name]
Read-p "Please input a number:" Var
Read-t 10-p "Please input a number:" Var
#!/bin/sh
While True
Do
Read-t 10-p "Please input number:" A B
Expr $a + 0 >/dev/null 2>&1
[$?-ne 0] && continue
Expr $b + 0 >/dev/null 2>&1
[$?-ne 0] && continue| | Break
Done
echo "A-B =$ (($a-$b))"
echo "A+b =$ (($a + $b))"
echo "A*b =$ (($a * $b))"
echo "A/b =$ (($a/$b))"
echo "A**b =$ (($a * * $b))"
echo "A%b =$ (($a% $b))"
To pass the parameter:
[email protected] shell]# cat read1.sh
#!/bin/sh
A= "$"
B= "$"
Usage () {
echo "Usage:sh $ NUM1 num2"
Exit 1
}
If [$#-ne 2];then
Usage
Fi
Expr $a + 0 >/dev/null 2>&1
[$?-ne 0] && Usage
Expr $b + 0 >/dev/null 2>&1
[$?-ne 0] && Usage
echo "A-B =$ (($a-$b))"
echo "A+b =$ (($a + $b))"
echo "A*b =$ (($a * $b))"
echo "A/b =$ (($a/$b))"
echo "A**b =$ (($a * * $b))"
echo "A%b =$ (($a% $b))"
Use of read in the shell