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
Copyright © ghostwritten 浙ICP备2020032454号 2022 all right reserved,powered by Gitbook该文件修订时间: 2022-06-22 15:37:40

results matching ""

    No results matching ""