In principle, recursion is never necessary. It can always be replaced by an iterative construct, such as while or until. Rewrite makepath (page 502) as a nonrecursive function. Which version do you prefer? Why?
What will be an ideal response?
function makepath2()
{
wd=$(pwd)
pathname=$1
while [[ $pathname = */* && ${#pathname} > 0 ]]
do
if [[ ! -d "${pathname%%/*}" ]]
then
mkdir "${pathname%%/*}"
fi
cd "${pathname%%/*}"
pathname="${pathname#*/}"
done
if [[ ! -d $pathname && ${#pathname} > 0 ]]
then
mkdir $pathname
fi
cd $wd
}
The recursive version is simpler: There is no need to keep track of the work-
ing directory and you do not have to handle the task of making the final
directory separately.
You might also like to view...
Shared workbooks cannot be marked as final
Indicate whether the statement is true or false
Various C statements enable you to specify that the next statement to be executed may be other than the next one in sequence. This is called __________.
a) change of order b) instruction skipping c) transfer of control d) rerouting