max.sh

来自「Shall高级编程」· Shell 代码 · 共 49 行

SH
49
字号
#!/bin/bash# max.sh: Maximum of two integers.E_PARAM_ERR=250    # If less than 2 params passed to function.EQUAL=251          # Return value if both params equal.#  Error values out of range of any#+ params that might be fed to the function.max2 ()             # Returns larger of two numbers.{                   # Note: numbers compared must be less than 257.if [ -z "$2" ]then  return $E_PARAM_ERRfiif [ "$1" -eq "$2" ]then  return $EQUALelse  if [ "$1" -gt "$2" ]  then    return $1  else    return $2  fifi}max2 33 34return_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 numbers are equal."else    echo "The larger of the two numbers is $return_val."fi    exit 0#  Exercise (easy):#  ---------------#  Convert this to an interactive script,#+ that is, have the script ask for input (two numbers).

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?