shell编程学习笔记四

shell函数


定义函数


定义函数的格式
function 函数名(){
  命令
}






在脚本中使用函数
示例代码如下:
hello(){
echo "hello there today date is `date`"
}


在脚本中使用函数
示例代码如下:
#!/bin/sh
#test20
#在脚本中使用函数
hello()
{
echo "Hello there today's data is `date`"
}
echo "now going to the function hello"
hello


echo "back from function"
执行结果:
[retacn@localhost tmp]$ ./test20
now going to the function hello
Hello there today's data is 2013年 01月 04日 星期五 03:13:47 PST
back from function


在函数文件中使用函数
创建函数文件
#!/bin/sh
#test21
#函数文件
findit(){
 if [ $# -lt l ]; then
 echo "usage :findit file"
 return 1
 fi
 find / -name $l -print




编辑执行shell函数


示例代码如下:


#!/bin/sh
#function.main
#查找文件
findit(){
if [ $# -lt l ];then
  echo "usage: findit file"
  return 1
fi
for loop
do
 find / -name $loop -print
done
}




定位函数
[root@localhost tmp]# . /function.main 


set命令查看函数是否被载入,


执行函数
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值