Thursday, February 23, 2006

Technical junk

OK, so this is not so interesting, but I think there is a limit to the number of nested while loops I can put into a C shell script (at least in my OS X implementation of C shell). I am writing a script to run my simulations, and when I put three nested while loops into a fourth, my code would run without incident, but when it got to the end of the largest loop, it would only run once. I double checked everything, and then I wrote a little code that only looped and incremented four variables. Lo and behold, the same thing happened, and the largest loop only happened once. I haven't found any documentation online, so it could be limited to my particular setup, or it could be a general C shell limit. To fix it, I changed the largest loop to a if statement with a goto command to head up to the top of the other loops. If anyone has any information about this, let me know.

2 comments:

Anonymous said...

Just so you know, almost no one scripts using C shell. In general, it's considered "harmful". I use it for my interactive shell, but all of my scripting is in sh (bash).

Post the text of your loop though so we can see what it does.

benhood said...

Wow. I had no idea. I wish somebody had mentioned that last year when I started writing scripts. The script I mentioned is pretty easy:

set h = 0
set i = 0
set j = 0
set k = 0
while($h <= 4)
while ($i <= 4)
while ($j <= 4)
while ($k <= 4)
echo $k
echo $j
echo $i
echo $h
@ k++
end
@ k=0
@ j++
end
@ j=0
@ i++
end
@ i=0
@ h++
end

And it only loops through the three inner loops. However, I am not so worried about it now. I got it to work with an if statement, and I guess I will take a look at bash for scripting. Thanks for your help.