I am trying to write a script that searches a directory and it’s subdirectories etc for files matching a given regular expression. So I have started by attempting to write a function to get the directories and subdirectories first. For some reason it currently only seems to get the first subdirectory in the specified directory.
Here is the function:
getDirs() {
cd "$1"
for i in *; do
if [ -d "$i" ]; then
echo "dir: $PWD/$i"
getDirs "$i"
fi
done
}
getDirs $path
Any ideas how to fix this?
This should do it, although
findis more efficient.