0

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

1
  • use the find command. Commented May 19, 2016 at 8:47

2 Answers 2

1

Do you mean something like

find -path "*foo/*/foo" 
Sign up to request clarification or add additional context in comments.

Comments

0
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.