tsch script - nested loop dynamic variable reference

L

lizardthefish

Guest
Hello again. I have looked far and wide for an answer to this one, but to no avail.

It's a syntax question ... I am trying to refer to a variable in a nested loop ( for loop inside a for loop)
I have a script to automate the creation of a directory structure. Quite a simple script actually. Just using Arrays to define the hard coded directory name suffixes within the script and asking for interactive input for directory name prefix that will be standard across entire tree and finally mkdir builds the tree.

Here is the desired structure:

Code:
       myMaindir
    _______|________
   |       |        |
 sub0     sub1     sub2
           |         |
        sub1sub0    sub2sub0
         ____|______
        |           |
 sub1sub0sub0     sub1sub0sub1



here is a condensed version of the code:


Code:
########## Arrays of directory names############
### Here are the arrays where I hard code the directory suffixes:
### Array of folders to be made in the main directory

dir0=( Account Web Print )


### Arrays of folders to be placed in the above subdirectories

sub1=( Art Code )


### Arrays of folders to be placed in the above subsubdirectories

sub1sub0=( Photoshop Illustrator )


########### The function to build the directories ############
## Excluded mkdir commands for the sake of getting this working first.

function createdirectories ()
{
	#would make main dir here then run following loop for subdirectories
	echo "adding dir Main"
	for md in 0 1 2 3 4
        do
		echo "adding dir ${dir[$md]}"
                for sd in 0 1 2 3 4
                do
			echo "adding dir ${sub{$md}[$sd]}"
                        for ssd in 0 1 2 3 4
                        do
                                echo "adding dir ${sub{$md}sub{$sd}[$ssd]}"
                        done
                done
        done
}



And a last question:

I feel silly having to define the length of the loop manually when it seems that I should be able to just run it for the length of the array. Is this possible in tsch scripting?


Thanks for any direction,

Lizard

Oh, another last thing. In my research I keep coming across comparisons between csh/tcsh and bourne shell scripting languages. Should I switch to Bourne or Korn? Are they better in the long run? I'm running Mac OS X.3. My main programming experience is in Actionscript for Flash and some PHP. I am just now digging into these shell scripting languages.



.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top