I have a list of files inside a directory and I want to make a bash script which uses a regular expression to check if every file name inside it has this syntax:
Where x are numbers.
Edit: I only need with the regex
The regular expression checks for any digit (
I would recommend you don't use bash for this but find instead. It will probably be faster, and it is certainly more portable (not all shells can deal with regular expressions):
It’s clunky, but this should be very portable:
#!/bin/sh for x in * do case "$x" in [0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9]_[0-9][0-9]_[0-9][0-9]) echo "$x matches" ;; *) echo "$x doesn’t match" esac done # And, to be annoyingly complete, for x in .* do echo "$x doesn’t match" done