当前位置: > shell编程 >

linux shell 编程6 函数获取参数

时间:2016-06-12 23:35来源:linux.it.net.cn 作者:IT
 
  1. #!/bin/sh  
  2. arg1=$1  
  3. arg2=$2  
  4. tellname ()  
  5. {  
  6. echo "this is  tellname funciton  and execute this  function tellname !"  
  7. echo "two  args: $arg1 , $arg2"  
  8. }  
  9. echo " execute function "  
  10. # execute  function   
  11. tellname  

其中的$1 就是表示获取的第一个参数  $2 就是获取的第二个参数,之后还会看到$# 等这些特殊符号,而其中的$#就是获取参数的总个数。 

传参数的方式和给Java中的main函数的args 传递参数一样在调用的时候传递参数,参数和参数之间使用空格。

注意调用函数的时候没有括号,只有名称!

 
(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容