bash 比较二个数字大小
#!/bin/bash
E_PARAM_ERR=198
EQUAL=199
max2()
{
if [ -z "$2" ]
then
return $E_PARAM_ERR
fi
if [ "$1" -eq "$2" ]
then
return $EQUAL
else
if [ "$1" -gt "$2" ]
then
return $1
else
return $2
fi
fi
}
echo "the first number:"
read first
echo
echo "the second number:"
read second
echo
max2 $first $second
return_val=$?
if [ "$return_val" -eq "$E_PARAM_ERR" ]
then
echo "need to pass two parameters to the function."
elif [ "$return_val" -eq "$EQUAL" ]
then
echo "the two number are equal."
else
echo "the larger of the two nubers is $return_val."
fi
E_PARAM_ERR=198
EQUAL=199
max2()
{
if [ -z "$2" ]
then
return $E_PARAM_ERR
fi
if [ "$1" -eq "$2" ]
then
return $EQUAL
else
if [ "$1" -gt "$2" ]
then
return $1
else
return $2
fi
fi
}
echo "the first number:"
read first
echo
echo "the second number:"
read second
echo
max2 $first $second
return_val=$?
if [ "$return_val" -eq "$E_PARAM_ERR" ]
then
echo "need to pass two parameters to the function."
elif [ "$return_val" -eq "$EQUAL" ]
then
echo "the two number are equal."
else
echo "the larger of the two nubers is $return_val."
fi