创建函数的格式,有两种:
function name { commands }
name() { commands }
#!/bin/bash
echo $(uname); #the global Variable
declare num=1000;
uname()
{
echo "test!";
((num++));
return 100;
}
testvar()
{
local num=10;
((num++));#
echo "the local num is:$num" ;
}
uname;
echo $? #the function uname value of returning
echo $num;
testvar;
echo $num;

本文介绍了Bash脚本中函数的基本创建格式及其使用方法,包括两种定义方式,并通过示例展示了如何定义函数、调用函数及获取返回值。
555

被折叠的 条评论
为什么被折叠?



