1

The following command detects if any of the staged files in git is myFile.js:

echo $(git diff --cached --name-only --diff-filter=ACM | egrep 'path/to/myFile.jsx?$')

But I want to detect any .js file in that folder. I tried this but it didn't work:

echo $(git diff --cached --name-only --diff-filter=ACM | egrep 'path/to/{*}.jsx?$')

How to add a wild card for the filename here?

2
  • 1
    You should almost never use echo $(somecommand) -- the echo and the $( ) mostly cancel each other out, except for some potential parsing weirdnesses in between them. Just run the command directly (unless you want those parsing weirdnesses for some reason). Commented Jun 25, 2020 at 21:41
  • thanks, I was just echoing for debugging purposes, in the actual code the whole part after the echo is set as a var @GordonDavisson Commented Jun 25, 2020 at 22:57

1 Answer 1

1

Replace:

egrep 'path/to/{*}.jsx?$'

with:

egrep 'path/to/.+\.jsx?$'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.