With a fairly minor change (in red, below) ntubski
's test program works fine:
$ cat greatest
# run this in a new directory
pushd gr &>/dev/null
echo "i = $i, greatest = $greatest"
rm -rf gr/
i = 11, greatest = 0008
Of course, adding the 3 is unnecessary if you explicitly set your base to ten...