shell函数功能
1. 函数
funtion fname() { //do something }
shell是自上而下,由左而右执行的。
#!/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]$
2. 函数参数传递
#!/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]$
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。