shell 函数

    技术2022-05-20  69

    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:


    最新回复(0)