Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash glob 简介 #64

Open
AndreGeng opened this issue Dec 31, 2020 · 0 comments
Open

bash glob 简介 #64

AndreGeng opened this issue Dec 31, 2020 · 0 comments

Comments

@AndreGeng
Copy link
Owner

基本

"*" 除了"/"之外的任意0或者多个字符
"?" 除了"/"之外的任意1个字符
"[...]" 匹配括号内的字符, e.g.

  • [abc] a或者b或者c
  • [a-zA-Z0-9]
  • [!ab] 除a或者b之外的字符
  • [^ab] 除a或者b之外的字符

注意:

  1. ""或者"?"默认都是不匹配"."开头的隐藏文件的,只有glob表达式也明确以"."开头时,
    才会匹配隐藏文件
    例如:a/.
    /c 可以匹配 a/.b/c, 但a/*/c是不会匹配a/.b/c的
  2. 当globstar选项打开时,"**"用来匹配『当前文件夹』和『所有的子文件夹』,
    当globstar选项未打开时,"**"不包含『当前文件夹』

扩展模式

如果bash设置了extglob选项, 会开启『扩展模式』
shopt -s extglob
新增下面的匹配规则

  1. !(pattern|pattern) 取反
  2. ?(pattern|pattern) 0或者1个pattern
  3. +(pattern|pattern) 1或者多个pattern
  4. *(pattern|pattern) 0或者多个pattern
  5. @(pattern|pattern) 匹配其中一个pattern

ps: 有没有觉得『扩展模式』下面,!,?,+,*的用法和正则表达式里的很像,只不过是放pattern前面了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant