📄 max.sh
字号:
#!/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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -