我写了一个bash脚本来比较两个数字,但是对于一些数字它给出了错误的答案。 例如,如果我输入2&2,它会给我返回"X大于Y"。
#!/bin/bash
read num1
read num2
if [ $num1 > $num2 ]
then
echo "X is greater than Y"
elif [ $num1 < $num2 ]
then
echo "X is less than Y"
elif [ $num1 = $num2 ]
then
echo "X is equal to Y"
fi
-gt
操作符表示>
,使用-lt
表示<
,使用-eq
表示=
。 - anubhava