Shell globbing excludes directory templates

Apart from the commands that can be used in connection with shell shells, I would like to exclude certain directory templates in all directories and subdirectories from the glob template.

Say I have this directory structure:

+-- a
    +-- a1
         +-- assets
                  +-- a1-1
                         +-- a1-1.js
                  +-- a1-2
                         +-- a1-2.js
    +-- a2
         +-- a2.js
+-- b
    +-- b1
         +-- b1-2
                +-- b1-2-3
                         +-- assets
                                  +-- b1-2-3.js
    +-- b.js
+-- c
    +-- c.js

I would like to list all js files that do not have assetsfiles in their paths.

What I have tried so far:

$ shopt -s globstar extglob
$ ls ./**/!(assets)/**/*.js

Not only did the above template fail, it even shows repetitive exits. I know I can do something like this:

$ ls ./**/*.js | grep -v "assets"

Or any other commands that can be transmitted over channels, I just want to get a clean shell wrapper template.

Expected Result:

a/a2/a2.js  
b/b.js  
c/c.js
+4
source share
3

. ** ( ), assets.

, :

.
|-- a
|   |-- a1
|   |   +-- assets
|   |       |-- a1-1
|   |       |   +-- a1-1.js
|   |       +-- a1-2
|   |           +-- a1-2.js
|   +-- a2
|       +-- a2.js
|-- assets
|   +-- xyz.js
|-- b
|   |-- b1
|   |   +-- b1-2
|   |       +-- b1-2-3
|   |           |-- assets
|   |           |   +-- b1-2-3.js
|   |           +-- test
|   |               |-- test2
|   |               |   +-- test3
|   |               |       +-- test4
|   |               |           +-- test4.js
|   |               +-- test.js
|   +-- b.js
|-- c
|   +-- c.js
+-- x.js

.js:

$ find . -name '*.js'
./x.js
./assets/xyz.js
./a/a2/a2.js
./a/a1/assets/a1-2/a1-2.js
./a/a1/assets/a1-1/a1-1.js
./c/c.js
./b/b.js
./b/b1/b1-2/b1-2-3/test/test2/test3/test4/test4.js
./b/b1/b1-2/b1-2-3/test/test.js
./b/b1/b1-2/b1-2-3/assets/b1-2-3.js

bash GLOBIGNORE, , .

, :

$ GLOBIGNORE='**/assets/**:assets/**:**/assets'
$ ls -1 **/*.js
a/a2/a2.js
b/b1/b1-2/b1-2-3/test/test2/test3/test4/test4.js
b/b1/b1-2/b1-2-3/test/test.js
b/b.js
c/c.js
x.js
+3

, ** . , **, !(assets), a1/assets/, !(assets) a1-1, ** , .

:

touch a/a1/x.js a/a2/y.js a/a3/z.js
ls ./*/!(a2)/*.js
ls ./**/!(a2)/**/*.js

ls , - .

+1

zsh:-) ~:

% setopt extended_glob
% ls -1 **/*.js~*assets*
a/a2/a2.js
b/b.js
c/c.js
0

All Articles