使用函数

文件名为: 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

posted @ 2015-09-08 15:58  todaytoday  阅读(205)  评论(0编辑  收藏  举报