In principle, recursion is never necessary. It can always be replaced by an iterative construct, such as while or until. Rewrite makepath (page 1066) 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...
A(n) ________ can be an organized group of data in a Word table, an Excel worksheet, an Access database table or query, or an Outlook contact list
Fill in the blank(s) with correct word
With selectors, a ____ serves as a flag character and separates the element selector from the name of the dependent class.
A. comma B. period C. space D. question mark
A ____ server is a machine that is placed in the DMZ to attract hackers and direct them away from the servers being protected.
A. flytrap B. DNS server C. honeypot D. bastion host
How can you get point text to wrap?
What will be an ideal response?