#!/bin/sh
fSum 3 2;
function fSum()
{
echo $1,$2;
return $(($1+$2));
}
fSum 5 7;
total=$(fSum 3 2);
echo $total,$?;
sh testfun1.sh
testfun1.sh: line 3: fSum: command not found
5,7
3,2
#!/bin/sh
echo $(uname);
declare num=1000;
uname()
{
echo "test!";
((num++));
return 100;
}
testvar()
{
local num=10;
((num++));
echo $num;
}
uname;
echo $?
echo $num;
testvar;
echo $num;
sh testfun2.sh
Linux
test!
100
1001
11
1001
#!/bin/bash
demoFun(){
echo "This is your first shell function!"
}
echo "Function begin..."
hello
echo "Function end!"输出:
Function begin...
This is your first shell function!
Function end!
#!/bin/bash
funWithReturn(){
echo "The function is to get the sum of two numbers..."
echo -n "Input first number: "
read aNum
echo -n "Input another number: "
read anotherNum
echo "The two numbers are $aNum and $anotherNum !"
return $(($aNum+$anotherNum))
}
funWithReturn
echo "The sum of two numbers is $? !"输出类似下面:
The function is to get the sum of two numbers...
Input first number: 25
Input another number: 50
The two numbers are 25 and 50 !
The sum of two numbers is 75 !
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有