Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 3
    Instead of the [ testing non-empty output from grep (unquoted is bad), use grep -q -- echo "$filename | grep -qP "$regex" && echo match || echo no match Commented Jan 22 at 22:22
  • 1
    Would select this as the best answer. Could you please align your answer with the question... the form is if [[ expression ]]; then ...; else ...; fi
    – rellampec
    Commented Jan 23 at 10:08
  • Thank you ! It's done
    – hidigoudi
    Commented Jan 23 at 10:38
  • Thanks @hidigoudi . The other answer (edited) offers a more complete explanation. I like of yours that went straight to address the target result, though. Here some reference on the bash if statements that explains the PCRE solution of the other answer. By the way, option -q (silent) gets to bring the exit status code to the if condition.
    – rellampec
    Commented Jan 23 at 11:44
  • No problem, I understand, thank you for the vote up !
    – hidigoudi
    Commented Jan 23 at 12:47