#!/bin/bash

dirs_per_level=10
DEBUG=0

function create_dirs
# this function creates the subdirectories and then
# recurses on each subdirectory until the bottom level is reached.
# create_level level base
# level is the level to create and base is the pathname of the starting point
{
    local nl
    local nd
    local base_name
    local dir_name
    local file_name

    if [ $DEBUG -gt 0 ]
    then
        echo "entering create_dirs("$1,$2")"
    fi

    declare -i nl=$1
    declare -i nd=$dirs_per_level
    declare base_name=$2
    declare dir_name


    # create subdirectories, if not in leaf dir
    nd=$dirs_per_level
    while [ $nd -gt 0 ] && [ $nl -gt 0 ] ; do
        if [ $DEBUG -gt 0 ]
        then
            echo -e "\tcreating dir("$nd,$base_name"L"$nl"D"$nd"/"")"
        fi
        mkdir $base_name"L"$nl"D"$nd"/"
        let nd=$(($nd-1))
    done

    # recurse over subdirectories
    nd=$dirs_per_level
    while [ $nd -gt 0 ] && [ $nl -gt 0 ] ; do
        if [ $DEBUG -gt 0 ]
        then
            echo -e "\trecursing create_dirs("$((nl-1)),$base_name"DIR"$nd"/"")"
        fi
        create_dirs $((nl-1)) $base_name"L"$nl"D"$nd"/"
        let nd=$(($nd-1))
    done
}

create_dirs 5 "test_dirs" 
