1 [root@localhost array]# cat function_locate.sh 2 #!/bin/bash 3 if [ $# -ne 3 ];then 4 echo "usage: `basename $0` part1 part2 part3" 5 exit 6 fi 7 8 fun1() { 9 echo "$(($1 * $2 * $3))" 10 echo $1 $2 $3 11 } 12 13 result=`fun1 $3 $2 $1` 14 echo "result is $result" 15 [root@localhost array]# sh function_locate.sh 16 usage: function_locate.sh part1 part2 part3 17 [root@localhost array]# sh function_locate.sh 2 3 4 18 result is 24 19 4 3 2 20 [root@localhost array]#
第二版:
1 [root@localhost array]# cat function_locate.sh 2 #!/bin/bash 3 if [ $# -ne 3 ];then 4 echo "usage: `basename $0` part1 part2 part3" 5 exit 6 fi 7 8 fun1() { 9 echo "$(($1 * $2 * $3))" 10 echo $1 $2 $3 11 } 12 13 result=`fun1 5 4 3` 14 echo "result is $result" 15 [root@localhost array]# sh function_locate.sh 16 usage: function_locate.sh part1 part2 part3 17 [root@localhost array]# sh function_locate.sh 1 2 3 18 result is 60 19 5 4 3 20 [root@localhost array]#
思想:shell程序的位置参数和函数的位置参数,2者是不同的概念。可以自定义2者之间的关联关系。