学习shell编程 – 9.函数

 #函数  
 myName(){  
   echo "I've forgot your name"  
 }  
   
 myName  #必须先定义函数,它能执行它

###########################
#函数可以接受参数,但参数不必声明

withArg(){
   echo "the first arg is $1"
}

withArg "hello"

##########################3
#函数的返回值
withReturn(){
  return 33
}

withReturn
echo $? #将打印33, "$?"就是上步函数调用得到的返回值

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.