funtion fname() { //do something }
#!/bin/bash # author : yonggang function print_it(){ echo -n "Your choice is : " } case $1 in "one") print_it; echo $1; ;; "two") print_it; echo $1; ;; "three") print_it; echo $1; ;; *) echo "Usage $0 (one|two|three)" ;; esac执行:
[work@www sh]$ sh func.sh two Your choice is : two [work@www sh]$ sh func.sh one Your choice is : one [work@www sh]$
#!/bin/bash # author : yonggang function print_param(){ echo "paramter number : " $# echo "first paramter : " $1 echo "second paramter : " $2 echo "all paramter : " $@ } print_param one two three运行:
[work@www sh]$ sh func.sh paramter number : 3 first paramter : one second paramter : two all paramter : one two three [work@www sh]$
原文地址:http://blog.csdn.net/yonggang7/article/details/40679111