#!/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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
  • 2021-11-13
  • 2021-12-15
  • 2021-10-11
  • 2022-12-23
猜你喜欢
  • 2021-06-03
  • 2022-12-23
  • 2021-06-15
  • 2021-12-10
  • 2022-12-23
  • 2021-12-18
相关资源
相似解决方案