In reference to this post on exiting a function in bash
Does a recursive bash function lose its ability to return after descending?
I tried to make simple example function to explain. This function is given a directory and looks for a .foo file with the directories base name. If it does not exist it might just need to be renamed but it needs to find it first. I could rewrite this of course. The find loop is the cause of need for the returns. I am just curious about the recursive nature of bash functions in this case.
given_directory=$"/home/bob"
some_function "$given_directory"
some_function () {
specific_foo_file=$"$1"/"$(basename "$1")".foo
if [ -f "$specific_foo_file" ] ; then
echo "do file stuff"
else
find . -name "*.foo"|while file ; do
if mv "$file" "$specific_foo_file" ; then
echo "renamed $file to $specific_foo_file"
some_function $given_directory
return 0
else
echo "could not rename $file"
return 1
fi
done
echo "can't find any .foo files, oh well"
fi
}
So far the echo at the end is always called if the rename was successful.
EDIT: For my environment I am using:
-bash-3.2$ uname -a
SunOS XXXXXXXXXX 5.10 Generic_150400-29 sun4v sparc SUNW,SPARC-Enterprise-T5120