New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

tsch script - nested loop dynamic variable reference


Post Reply New Thread Subscribe

 
Thread Tools
lizardthefish
Guest
 
Posts: n/a

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.



.
QUOTE Thanks

Post Reply New Thread Subscribe


« NOOB Q's | nVIDIA Cg on the mac »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

All times are GMT -4. The time now is 04:43 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?