我编写了这个脚本来比较bash中的2个数字,但它给了我一些数字的错误答案。 一样,如果我给它2 & 2输入,它给了我 “X大于Y”比较bash脚本中的数字
#!/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
对于比较数字,使用''为>','-lt' -gt'运营商'<'和'-eq'为'=' – anubhava
@anubhava但输入“2和3”却给出了错误的答案 – Kiana