Issue
Assume that I have the following directory structure:
file.txt
file.css
file.js
directory/file.txt
directory/file.css
directory/file.js
directory/subdirectory/file.txt
directory/subdirectory/file.css
directory/subdirectory/file.js
I want to be able to find all of the txt
and css
files in all directories (ideally without using find
because I want the command that I write to be extensible). The list of file extensions should be in a variable named FILE_PATTERN
.
The command should ultimately output:
directory/subdirectory/file.css
directory/subdirectory/file.txt
directory/file.css
directory/file.txt
file.css
file.txt
But each globbing pattern I am trying isn't returning the result:
$ FILE_PATTERN="{**/,}*.{css,txt}"
$ echo $FILE_PATTERN
# FAILS: Returns 0 results
$ FILE_PATTERN={**/,}*.{css,txt}
$ echo $FILE_PATTERN
# FAILS: Returns 0 results
$ echo {**/,}*.{css,txt}
# FAILS: Only returns:
directory/file.css directory/file.txt file.css file.txt
Any suggestions?
Solution
Not sure what you have against find, it can be made very extensible with a little effort (even on a MAC):
FILE_PATTERN=(txt css)
IFS='|'
find -E -iregex ".*(${FILE_PATTERN[*]})"
I do not have a mac to play with, but I think the -E option should work for you, if not, have a look at the man page :)
Answered By - grail Answer Checked By - Willingham (WPSolving Volunteer)