仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 873|回复: 6
打印 上一主题 下一主题

[shell编程] 带来一篇shell中利用Bash中的globstart选项

[复制链接]
透明 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-14 20:17:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的好朋友们!在利用一些下令时(如:ls、git),恰好碰到一些需求是想很便利地遍历一切的目次和文件,厥后经由搜刮,终究找到了一个“奇妙”的通配符“**”(两个星号),在设置了Bash的globstar选项后,**就能够婚配任以后何目次(包含子目次)和个中的文件。以是,懂得了一下globstar这个选项,当未设置globstar时,**通配符的感化和*是不异的,而设置了globstar后,**的婚配局限分歧了(更广一些)。注重:globstar是Bash4.0才引进的选项,之前的老版本是不撑持的,利用“bashCversion”可产看以后利用的Bash的版本。
关于glob这个词,我也以为猎奇,中文欠好注释,大抵就是“对通配符睁开”的意义,以下的英文吧:
Inshell-speak,globbingiswhattheshelldoeswhenyouuseawildcardinacommand(e.g.*or?).Globbingismatchingthewildcardpatternandreturningthefileanddirectorynamesthatmatchandthenreplacingthewildcardpatterninthecommandwiththematcheditems.

在bash的manpage中,对globstar的申明提到只两次,说的都是统一件事变,以下:
  1. PathnameExpansion......*Matchesanystring,includingthenullstring.Whentheglobstarshelloptionisenabled,and*isusedinapathnameexpansioncontext,twoadjacent*susedasasinglepatternwillmatchallfilesandzeroormoredirectoriesandsubdirectories.Iffollowedbya/,twoadjacent*swillmatchonlydirectoriesandsubdirectories.......globstarIfset,thepattern**usedinapathnameexpansioncontextwillmatchafilesandzeroormoredirectoriesandsubdirectories.Ifthepatternisfollowedbya/,onlydirectoriesandsubdirectoriesmatch.
复制代码
写了个测试和进修globstar的shell剧本以下:
  1. #!/bin/bash<prelang="Bash">functionshow(){foriin**doecho$idone}cd/root/jay/echo"------------------------"echo"disableglobstaroption:"#globstarisdisabledbydefaultshopt-uglobstarshowecho"------------------------"echo"enableglobstaroption:"shopt-sglobstarshow
复制代码
实行下面测试globstar的shell剧本,看它的输入了局,就很简单了解globstar了,以下:
  1. [root@smilejayjay]#./test_globstar.sh------------------------disableglobstaroption:dir1dir2file1file2index.htmltest_shopt.sh------------------------enableglobstaroption:dir1dir1/file3dir2dir2/file4file1file2index.htmltest_shopt.sh
复制代码
参考材料:
http://www.linuxjournal.com/content/globstar-new-bash-globbing-option
bash4引进的新feature:http://wiki.bash-hackers.org/bash4
http://wiki.bash-hackers.org/syntax/expansion/globs


如果您觉得本篇CentOSLinux教程讲得好,请记得点击右边漂浮的分享程序,把好文章分享给你的好朋友们!
金色的骷髅 该用户已被删除
沙发
发表于 2015-1-15 15:26:48 | 只看该作者

带来一篇shell中利用Bash中的globstart选项

顶顶更健康
板凳
发表于 2015-1-25 20:42:38 | 只看该作者
我想即使Linux高手也很难快速准确精练的回答你。
分手快乐 该用户已被删除
地板
发表于 2015-2-4 12:04:28 | 只看该作者
编程学习及开发,Linux是免费,开源的操作系统,并且可开发工具相当多,如果您支持自由软件,一定要同广大热爱自由软件人士一同为其不懈努力。
简单生活 该用户已被删除
5#
发表于 2015-2-9 22:34:19 | 只看该作者
linux鸟哥的私房菜,第三版,基础篇,网上有pdf下的,看它的目录和每章的介绍就行了,这个绝对原创!
透明 该用户已被删除
6#
 楼主| 发表于 2015-3-10 01:41:11 | 只看该作者
直到学习Linux这门课以后,我才知道,原来我错了。?
乐观 该用户已被删除
7#
发表于 2015-3-24 05:50:33 | 只看该作者
随着实验课程的结束,理论课也该结束了,说实话教OS的这两位老师是我们遇到过的不错的老师(这话放这可能不太恰当).
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-4-28 17:27

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表