Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
tsch script - nested loop dynamic variable reference
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="lizardthefish" data-source="post: 23697"><p>Hello again. I have looked far and wide for an answer to this one, but to no avail.</p><p></p><p>It's a syntax question ... I am trying to refer to a variable in a nested loop ( for loop inside a for loop)</p><p>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.</p><p></p><p>Here is the desired structure:</p><p></p><p>[CODE]</p><p></p><p> myMaindir</p><p> _______|________</p><p> | | |</p><p> sub0 sub1 sub2</p><p> | |</p><p> sub1sub0 sub2sub0</p><p> ____|______</p><p> | |</p><p> sub1sub0sub0 sub1sub0sub1</p><p></p><p></p><p></p><p>[/CODE] </p><p></p><p></p><p></p><p>here is a condensed version of the code:</p><p></p><p></p><p>[CODE]</p><p></p><p>########## Arrays of directory names############</p><p>### Here are the arrays where I hard code the directory suffixes:</p><p>### Array of folders to be made in the main directory</p><p></p><p>dir0=( Account Web Print )</p><p></p><p></p><p>### Arrays of folders to be placed in the above subdirectories</p><p></p><p>sub1=( Art Code )</p><p></p><p></p><p>### Arrays of folders to be placed in the above subsubdirectories</p><p></p><p>sub1sub0=( Photoshop Illustrator )</p><p></p><p></p><p>########### The function to build the directories ############</p><p>## Excluded mkdir commands for the sake of getting this working first.</p><p></p><p>function createdirectories ()</p><p>{</p><p> #would make main dir here then run following loop for subdirectories</p><p> echo "adding dir Main"</p><p> for md in 0 1 2 3 4</p><p> do</p><p> echo "adding dir ${dir[$md]}"</p><p> for sd in 0 1 2 3 4</p><p> do</p><p> echo "adding dir ${sub{$md}[$sd]}"</p><p> for ssd in 0 1 2 3 4</p><p> do</p><p> echo "adding dir ${sub{$md}sub{$sd}[$ssd]}"</p><p> done</p><p> done</p><p> done</p><p>}</p><p></p><p>[/CODE]</p><p></p><p></p><p></p><p>And a last question:</p><p></p><p>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?</p><p></p><p></p><p>Thanks for any direction,</p><p></p><p>Lizard</p><p></p><p>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.</p><p></p><p></p><p></p><p>.</p></blockquote><p></p>
[QUOTE="lizardthefish, post: 23697"] 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 [/CODE] 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 } [/CODE] 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]
Verification
What is Apple's smallest desktop computer called?
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
tsch script - nested loop dynamic variable reference
Top