I'm not sure you could call it a real return either -- more of a courtesy return.
Here's the function I think is missing some lines:
Code:
function searchme () {
#Start the search
echo -e "What folder do you wish to search?\n(space or 'top' -- current directory recursion)"
read tdir
if [[ ! -d "$tdir" ]] && [ "$tdir" == " " ] || [ "$tdir" == "top" ]; then tiptop; fi
if [[ ! -d "$tdir" ]]; then trapr ; fi
echo "Okay, give me the search string."
read tbool
echo -ne "\n$mydate Searched string $tbool in folder $tdir of parent folder $survey.\n" >> ~/searcher.log
cd "$tdir"
e=$(ls |grep $tbool)
ecount=$(ls -1 | grep $tbool | wc -l)
if [[ "$ecount" != "0" ]]; then
echo "$ecount files found." >> ~/searcher.log
else
echo "No results returned." >> ~/searcher.log
fi
echo "Checking..."
sleep 0.5
if [[ -z "$e" ]] || [[ "$ecount" == "0" ]];
then
echo -ne "No files found with the search string $tbool in the folder $tdir.\nSorry.\n"
else
ls *$tbool*
echo "Done. Details logged."
fi
cd ../
}
It's the first part of the last
if/then/fi conditional, just above the
else, that I think needs a return command of some kind to follow it.
The operative part of the script, outside the several functions that make up most of it, reads like this:
Code:
read -e -p "Another search? {y/n} " goagain
if [[ "$goagain" != "n" ]]; then
echo
searchme
else
echo "Exiting."
exit 1
fi
There's the "courtesy" part -- asking if the user wants to run another search. As the whole script runs now, if no file matching the search string in the valid (or valid
ated -- there's another function that checks for this) folder selected, then the script quits instead of returning to the part at the end.
What would be the best method of guaranteeing a return to "chute" the user down to that primary routine?
BZT