免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1753 | 回复: 2
打印 上一主题 下一主题

shell 函数解惑 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-06-22 22:15 |只看该作者 |倒序浏览
下面创建包容函数的函数文件并将之载入shell,进行测试,再做改动,之后再重新载入.
函数文件名为functions.main,内容如下:
$ vi functions.main
#!/bin/bash
#functions.main
#findit:this is front end for the basic find command
findit() {
if [ $# -lt 1 ]; then
echo "usage:findit file"
return 1
fi
find / -name $1 -print
19.8 定位文件
定位文件格式为:
./pathname/filename
现在文件已经创建好了,要将之载入shell,键入:
. /functions.main 或.  functions.main(应该是后者正确)
点-空格-斜线-文件名,或点-空格-文件名

上面是书上的说明,但是具体执行的时候是如何一个执行法?
比如我常见了一个文件sh1.sh 。里面包含上面的函数,之后如何调用执行啊?

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/LUOPING1984 ... /07/23/4369344.aspx

论坛徽章:
0
2 [报告]
发表于 2010-06-23 03:25 |只看该作者
就像调用一个命令一样

论坛徽章:
0
3 [报告]
发表于 2010-06-23 08:15 |只看该作者
回复 1# spring_hz
  1. root@localhost lx]# cat task.sh
  2. #!/bin/sh
  3. #task.sh

  4. findit()
  5. {
  6.         find /home/shilei/shell/cu/ -name "*.sh" -print
  7. }
复制代码
  1. [root@localhost lx]# source task.sh
  2. [root@localhost lx]# findit
  3. /home/shilei/shell/cu/jd5/cmd.sh
  4. /home/shilei/shell/cu/jd7/shel.sh
  5. /home/shilei/shell/cu/lx/TASK.sh
  6. /home/shilei/shell/cu/lx/com.sh
  7. /home/shilei/shell/cu/lx/task.sh
  8. /home/shilei/shell/cu/lx/sh.sh
  9. /home/shilei/shell/cu/jd10/sh.sh
  10. /home/shilei/shell/cu/s.sh
  11. /home/shilei/shell/cu/jd9/sh.sh
  12. /home/shilei/shell/cu/sh.sh
  13. [root@localhost lx]#
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP