Reputation: 1
i asked to write script that searching recursively for files that match to the pattern ".foo" BUT the only files which exist in directories that match to the same pattern ".foo". i tried: script name : search_for_foo
function foo_search {
while read line; do
echo "$line”
done < "$1"
}
for file in ${*:1}; do
if [[ $file == *.foo* ]]; then
if [[ -f "$file" ]]; then
foo_search $file
fi
if [[ -d "$file" ]]; then
search_for_foo $file/*
fi
fi
done <"$1"
it has to work this way : ./search_for_foo --some_file--
thanks in advance
Upvotes: 0
Views: 34
Reputation: 18371
location=$1
pattern=$2
dir=$(find $location -type d -name "*.$pattern")
ls -lrt $dir|grep ^- |awk '{print $NF}'
run like ./script.sh /location/directory/ pattern
Upvotes: 0