使用函数

文件名为: test5.sh 

#!/bin/bash
# using the return command in a function

function db1 {
read -p "Enter a value:" value
echo "docubling the value"
return $[ $value * 2 ]
}
db1
echo "The new value is $?"

运行 sh test5.sh 

输出为 Enter a value: 键盘输入23后输出

docubling the value
The new value is 46

 注:输入的数字大于125则会返回错误,因为输出'$?'的值最大不超过256

原文地址:https://www.cnblogs.com/jacson/p/4792023.html