HELP NEEDED : RECURSIVE SHELL PROCEDURE

HELP NEEDED : RECURSIVE SHELL PROCEDURE

Post by M. Lai » Fri, 13 Mar 1992 15:44:57



The following procedure is from the book "UNIX Programming, Methods and
Tools",by James F.Peters III

$cat > mirror
 #experiment with recursion

if [ $1 -ne 0 ]
then
        echo 'count =' $1
        mirror `expr $1 -1`
fi
echo ' old value of $1 = ' $1
ctrl-d
$

A sample run of mirror is as follows:
$ mirror 3
count = 3
count = 2
count = 1
   old value of $1 = 0
   old value of $1 = 1
   old value of $1 = 2
   old value of $1 = 3
$

How should the procedure mirror be modified so that it runs
recursively without creating a succession of subshells?

Please send your replies to :