shell 函数

来源:互联网 发布:游戏脚本制作软件 编辑:程序博客网 时间:2024/05/16 07:33

test.sh

add()
{
  result=`expr $1 + $3`
  echo "$result"
}
minus()
{
    result=`expr $1 - $3`
    echo "$result"
}
main()
{
    case $2 in
        "+")
           add $@
           ;;
        "-")
           minus $@
          ;;
    esac
}
main $@

 

运行结果:

root@May:~/test# ./test.sh 4 + 6
10
root@May:~/test# ./test.sh 4 - 6
-2
root@May:

原创粉丝点击