Linux下的shell编程问题

发布网友 发布时间:2022-04-23 08:52

我来回答

3个回答

热心网友 时间:2022-06-18 15:15

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

热心网友 时间:2022-06-18 15:16

#!/bin/sh

##input 3 numbers
[ $# -ne 3 ] &&
{
echo "Usage: `basename $0` <num1> <num2> <num3>"
exit 1
}
##set the values
a=$1
b=$2
c=$3

#compare the values
[ $a -lt $b ] && [ $a -lt $c ] &&
{
echo "$a is the least"
}
[ $b -lt $a ] && [ $b -lt $c ] &&
{
echo "$b is the least"
}
[ $c -lt $a ] && [ $c -lt $b ] &&
{
echo "$c is the least"
}

热心网友 时间:2022-06-18 15:16

#!/bin/sh

[ $# -ne 3 ] && ecoh "Usage: sh `basename $0` x y z" && exit 1
echo "${x:=$1} ${y:=$2} ${z:=$3}" | xargs -n1 | sort -n | head -n1

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com