I'm studying the bash shell and lately understood i'm not getting right recursive calls involving file searching- i know find is made for this but I'm recently asked to implement a certain search this way or another.
I wrote the next script:
#!/bin/bash
function rec_search {
for file in `ls $1`; do
echo ${1}/${item}
if[[ -d $item ]]; then
rec ${1}/${item}
fi
done
}
rec $1
the script gets as argument file and looking for it recursively. i find it a poor solution of mine. and have a few improvement questions:
- how to find files that contain spaces in their names
- can i efficiently use
pwdcommand for printing out absolute address (i tried so, but unsuccessfully) - every other reasonable improvement of the code
ls!findis not a built-in command in any shell.GNU findutils