Why does my bash pattern match not work properly when 'piped' through nodejs exec?

406 views Asked by At

I am running following command on git bash (windows)

paste --delimiter=\\n --serial src/libs/**/*[^.spec].js > test.js

with shopt:

globstar on
extglob on

This successfully concats all js files recursively from src/libs on, except all *.spec.js files when executed from terminal.

However, when I run this command through grunt-shell (https://github.com/sindresorhus/grunt-shell) it works also but : [^.spec] is ignored. Means all my *.spec.js files get into test.js too.

1

There are 1 answers

2
Nahuel Fouilleul On BEST ANSWER

With extglob (and globstar) the following syntax is correct the other [^..] is a negative character set.

paste --delimiter=\\n --serial src/libs/**/!(*.spec).js > test.js

Otherwise it can be done with find

find src/libs -name '*.js' ! -name '*.spec.js' -exec paste --delimiter='\n' --serial {} + > test.js

Is there any difference with

find src/libs ! -name '*.spec.js' -name '*.js' -exec cat {} + > test.js