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: