# 函数定义 detect platform, no params
function func_utils_platform_name() {
platform="win"
uname_result=`uname`
if [ "$uname_result" = "Linux" ]; then
platform="linux"
elif [ "$uname_result" = "Darwin" ]; then
platform="mac"
fi
echo $platform #通过echo将值输出
}
# 函数调用
platform=`func_utils_platform_name` # 通过命令调用接收echo的值
if [ "$platform" = "win" ]; then
# other codes
fi
函数返回字符串
shell的函数默认是只能返回numric类型,数字类型。如果想返回字符串,则可以把函数当作命令去调用: