2

I wanted to create a glob expression to ignore any file inside a dont_doc directory, but when I tried using using GLOBIGNORE to do it, it did not work:

$ GLOBIGNORE='**/dont_doc/**'
$ echo dont_doc/**
dont_doc/customBlockHelpers.hbs.js dont_doc/RoClasses.js dont_doc/RoEnums.js dont_doc/RoModules.js dont_doc/RoTypes.js

this is what I want to happen:

dont_doc/doc.js #Fail
dont_doc/lol/doc.js #Fail
lol/dont_doc/doc.js #Fail
lol/dont_doc/lol/doc.js #Fail
lol.js #Succsed
index.html #Fail
oof/lol.js #Succsed

how do I fix this?

Edit: I also want to ignore the node_modules folder

1 Answers1

3

Try with:

GLOBIGNORE='dont_doc:*/dont_doc:dont_doc/*:*/dont_doc/*'

Note that it doesn't stop bash from looking into those directories, it just removes the entries matching those patterns from the glob expansion. So here we have 4 patterns separated with :, one to exclude dont_doc alone, one to exclude ones ending in /dont_doc, one to exclude ones starting with dont_doc/, and the last one to exclude ones containing /dont_doc/.

It's similar to what the ~ operator does in zsh -o extendedglob (like in print -rC1 -- **/*~(|*/)dont_glob(/*|))

In ksh93, you just need FIGNORE=dont_doc for dont_doc directory entries to be ignored. Like zsh -o extendedglob's (^dont_glob/)#^dont_glob, though beware that in ksh93, setting FIGNORE also disables the hiding of filenames starting with ..

Note that ** only makes sense if you enable the globstar option to enable zsh-style recursive globbing.

If you turn the extglob option on in bash (shopt -s extglob), a subset of ksh's extended glob operators become available, and you can shorten the pattern to:

GLOBIGNORE='?(*/)dont_glob?(/*)'

Or to exclude more than one directory:

GLOBIGNORE='?(*/)@(dont_glob|node_modules)?(/*)'
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501