Shell函数语法

                         Shell函数语法                               

定义函数:

function   函数名(){

  指令。。。

}

调用函数,方法1:

函数名

 

调用函数,方法2:

函数名  参数一   参数二

 

return在函数里面使用会跳出函数并返回一个值;

 

函数应用:
[root@slavedb test]# 
[root@slavedb test]# cat a.sh 
#!/bin/bash
. /etc/init.d/functions
freddy (){
        echo "freedy"
}
freddie (){
        echo "freddie"
}

[root@slavedb test]# cat b.sh 
#!/bin/bash
[ -x /tmp/test/a.sh ]&& . /tmp/test/a.sh ||exit
freddy
freddie
[root@slavedb test]# 

 

posted @ 2016-04-25 14:53  唐胜伟  阅读(169)  评论(0编辑  收藏  举报