话不多说一顿操作
1.函数中return返回值
root@ubuntu-linux:~/shell# vim test.sh
func1() {
reap -p "Please enter your number:" num #输入结果赋值为num
echo "I'm going to multiply the Numbers"
return $[ $num *2 ] #返回值==调用输入结果*2
}
func1 #调用函数
echo "Your answer is $?" # $? 控制数值在1~255中 不然会报错会显示
# 脚本结果
root@ubuntu-linux:~/shell# vim test.sh
root@ubuntu-linux:~/shell# bash test.sh
Please enter your number:22
I'm going to multiply the Numbers
Your answer is 44
read -t 等待时间,如果时间过了就会返回一个非零的状态码