It is currently Fri, 23 Oct 2020 19:04:44 GMT



 
Author Message
 Syntax error in nested loop?
Hi NG,

I'm a total rookie at this csh-writing, so I'd very appreciate some
help from the wizards :o)

I have a simple script which calls an executable a number of times
(changing the calling parameters for each cycle) in a while-loop, like
this:

... setting some constants first...

while ( $x <= 31 )

        # compose date
        set date = ${odate}$x

        # run program with date as parameter
        # call program happens here

        # increment day
        @ x = $x + 1
end

That works just fine. I now need to nest this loop in another while
loop, cycling through the months as well:

while ($month <= 12)
    while ( $x <= 31 )

        # compose date
                set date = ${odate}$x
                set date = ${date }$month

        # run program with date as parameter
        # call program happens here

        # increment day
        @ x = $x + 1
   end

   # increment month
   @ month = $month + 1

end

But now I get a syntax error after the last line (i.e. the last end;  "
'end of file' unexpected"..? Any ideas?

Thanks in advance!

best,

M.L.



 Fri, 11 Jul 2008 05:47:47 GMT   
 Syntax error in nested loop?

    Is this csh? It is not recommended for scripting. See:

        <http://www.grymoire.com/Unix/CshTop10.txt>
        <http://www.grymoire.com/Unix/Csh.html#uh-0>
        <http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/>

      In a POSIX shell:

month=1
while [ $month -le 12 ]
do
    x=1
    while [ $x -le 31 ]
    do

        # compose date
        date=${odate}$x
        date=${date}$month

        # run program with date as parameter
        # call program happens here

        # increment day
        x=$(( $x + 1 ))
   done

   # increment month
   month=$(( $month + 1 ))

done

--
   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence



 Fri, 11 Jul 2008 07:26:11 GMT   
 Syntax error in nested loop?
Hi,

Thanks! I'll give it a try.

Best,

M.L.



 Fri, 11 Jul 2008 08:55:13 GMT   
 Syntax error in nested loop?

   You'll give what a try? Please read <http://cfaj.freeshell.org/google>.

--
   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence



 Fri, 11 Jul 2008 09:55:08 GMT   
 Syntax error in nested loop?
I'll try what you suggested.


 Fri, 11 Jul 2008 20:03:16 GMT   
 
   [ 5 post ] 

Similar Threads

1. access.conf syntax error without a syntax error

2. Nested ctrl statements syntax confusion

3. nested loops in bash

4. Help: Fastest Nested-Loops

5. Nested Awk loops?

6. performance improvement (nested loop)

7. breaking out of nested loops, pipelines, and coprocesses

8. Nested loops in scripts

9. while/getopts nested while loop

10. nest while loops (K-shell)


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software