Reputation: 581
I have been looking into this and can't seem to find an answer.
I have a file name stored in string FILENAME
FILENAME="my%fi;le.dat"
I am traversing a directory trying to find files that contain any of these characters:
BAD_CHARS="%^();,"
How can I determine (with bash or tool) if any (1 or more) of those characters are in the filename?
Upvotes: 0
Views: 44
Reputation: 92854
With bash
's regex matching =~
:
$ [[ "$FILENAME" =~ ["$BAD_CHARS"] ]] && echo "bad name!" || echo "valid name"
bad name!
where ["$BAD_CHARS"]
forms regex character class [%^();,]
Upvotes: 2