shell 比较大小

shell 比较大小

三个数值由小到大:

compare1.sh

#!/bin/bash

echo -n "Enter three number:"
read a b c
if [ $a -gt $b ];then
t=$a;a=$b;b=$t;
fi
if [ $a -gt $c ];then
t=$a;a=$c;c=$t;
fi
if [ $b -gt $c ];then
t=$b;b=$c;c=$t;
fi
echo "From small to big:$a,$b,$c"

执行:

$ bash compare1.sh 
Enter three number: 2 4 3
From small to big:2,3,4

猜你喜欢

转载自blog.csdn.net/xixihahalelehehe/article/details/125161802