linux shell (6) -脚本函数

linux shell (6) -脚本函数

2015.10

**** http://www.jikexueyuan.com/course/1622.html

欢迎提问!

基本函数

函数定义两种方式

linux shell (6) -脚本函数

使用

直接用函数名。

linux shell (6) -脚本函数

状态吗

linux shell (6) -脚本函数

返回值

linux shell (6) -脚本函数

函数中变量的使用

函数参数

linux shell (6) -脚本函数

$# 表示参数个数
$? 表示脚本返回状态码

数组参数

1

linux shell (6) -脚本函数

linux shell (6) -脚本函数

2

linux shell (6) -脚本函数

linux shell (6) -脚本函数

$0 = 整个数组
$1 = 第一个元素
$2 = 第二个元素

[email protected]的使用

linux shell (6) -脚本函数

数组作为返回值

linux shell (6) -脚本函数

变量作用域

全局

linux shell (6) -脚本函数

result在函数外可以访问是全局变量。

local定义局部变量

linux shell (6) -脚本函数

库函数

linux文件不需要扩展名标识,与windows不同

引用函数库文件两种写法

linux shell (6) -脚本函数

linux shell (6) -脚本函数

linux shell (6) -脚本函数

定义全局库函数 写入.bashrc文件