Skip to content
Advertisement

How to grep within a loop to exclude?

I have a NPM_RESERVED_SCOPE that contains a comma-separated list of forbidden scope.

I have a NPM_ALLOWED_DEV_DEPENDENCIES_PACKAGES that contains a comma-separated list of exception.

JavaScript

I want this script to passe if the devDependencies does not contains any of the NPM_RESERVED_SCOPES, except the list of exception.

This is the file package.json

JavaScript

How can I do?

Advertisement

Answer

Convert the lists into extended patterns by replacing , with | and wrapping the list in @(...).

JavaScript

Now pattern matching can replace the nested for loops.a = @(x|y|z) if a matches any one of the patterns x, y, or z.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement