Linux下的shell编程问题

来源:百度知道 编辑:UC知道 时间:2024/05/31 02:54:42
设有三个变量:x,y,z,要求用户输入对这个三个变量赋值,然后比较它们的大小,并且输出最小值。谢谢大家帮助!重赏!!

1 #!/bin/sh
2
3 #对x,y,z赋值
4 echo "Please input x !"
5 read x
6
7 echo "Please input y !"
8 read y
9
10 echo "Please input z !"
11 read z
12
13 echo "OK x = $x y = $y z = $z"
14 echo ""
15
16 #比较大小
17 if [ $x -lt $y ]
18 then
19 if [ $x -lt $z ]
20 then
21 echo "The x[$x] is the least !"
22 else
23 echo "The z[$z] is the least !"
24 fi
25 else
26 if [ $y -lt $z ]
27 then
28 echo "The y[$y] is the least !"
29 else
30 echo "The z[$z] is the least !"
31 fi
32 fi

#!/bin/sh

##input 3 numbers
[ $# -ne 3 ] &&
{
echo "Usage: `basename $0` <num1> <num2> <num3>"