UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 4th, 2004, 10:39 PM
lizardthefish lizardthefish is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 3 lizardthefish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 0
Question tsch script - nested loop dynamic variable reference

Hi all. I have looked and looked for an answer here, 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.



.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > tsch script - nested loop dynamic variable reference


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway