【发布时间】:2021-12-10 07:11:36
【问题描述】:
我正在准备用于比较 3 个数字的 shell 代码。 我的代码如下
#!/bin/bash
echo "enter any 3 numbers"
read num1
read num2
read num3
if [ $num1 -gt $num2 ]
then
if [ $num1 -gt $num3 ]
then
echo "$num3 is greater than $num1 & $num1"
fi
elif [ $num2 -gt $num1 ]
then
if [ $num2 -gt $num3 ]
then
echo "$num2 is greater than $num1 & $num3"
fi
elif [ $num3 -gt $num1 ]
then
if [ $num3 -gt $num2 ]
then
echo "$num3 is greater then $num2 &$num1"
fi
else
echo "invalid"
fi
如果我输入第 1 个或第 2 个最高数字,那么它给出了正确的输出,但是如果我输入第 3 个最高数字,它就不会被评估。第二个 elif 语句不会被评估。
【问题讨论】:
标签: linux bash shell nested sh