shell scripting: help appreciated

no at spam at mgedv.net nospam at mgedv.net
Tue Jul 4 10:28:36 UTC 2006


> -----Original Message-----
> From: owner-freebsd-questions at freebsd.org 
> [mailto:owner-freebsd-questions at freebsd.org] On Behalf Of Parv
> Sent: Monday, July 03, 2006 7:50 PM
> To: no at spam@mgedv.net
> Cc: freebsd-questions at freebsd.org
> Subject: Re: shell scripting: help appreciated
> 
> in message <006701c69e7a$7898db00$01010101 at avalon.lan>,
> wrote no at spam@mgedv.net thusly...
> >
> > /bin/sh stops working correctly with a content-controlled do-loop.
> > 
> > the shell-script layout is as follows:
> > (it's not that trivial, just to show the meaning)
> > ---------------------------------------------------------------
> > /test/foo.conf (originally ~60 lines):
> > test1         testval1                optional_testval1
> > test2         testval2                optional_testval2
> > 
> > /test/foo.sh (this is the original loop code):
> > cat "$g_dir_etc/compile.lst"|\
> ...
> ( some pipeline )
> ...
> > while read gh_name gh_src gh_srcdir
> > do
> >       <set some vars here>
> >       /bin/sh -c subprogram.sh $h_val1 $h_val2 $h_opt1;
> >       <do some stuff here>
> > done;
> > 
> > /test/foo_sub.sh:
> > <we do very much stuff in here, like compiling programs etc...>
> > ---------------------------------------------------------------
> > 
> > if i change the line
> >       /bin/sh -c subprogram.sh $h_val1 $h_val2 $h_opt1;
> > to
> >       echo /bin/sh -c subprogram.sh $h_val1 $h_val2 $h_opt1;
> > the program loops for all records in the foo.conf correctly.
> > 
> > if i remove the "echo" keyword, the sub-script get's executed,
> > but the shell terminates as if there were lesser records in
> > the foo.conf file!
> > i scripted as many debug messages as possible, for every loop
> > they get executed and there are no errors/etc... happening.
> > and interestingly, the execution stops always on the same record!
> > if i comment out some records of my foo.conf, the sub-shell gets
> > executed for more records.
> 
> So, what is it exactly in the records (and/or values given to
> subprogram.sh) where the execution stops?
> 

it's not depending on the record. the layout of each record is 2
fixed an one variable field of data which is then put together to
directory/file-names inside the subprogram.
the subprogram just simply should loop for each record inside the
controlfile, which is done correctly if i change the subprogram to
an just "say hello" script.
if i run the really program, the loop stops (not immediately after
calling the subprogram, it just normal finishes the loop) after
working on lesser records as there are inside the .conf file.

no idea of what's going on.

btw., for each record - after the subprogram has successfully worked
on it a "done" flag is set and the subprogram is not called again
for this record.
looping the main program again and again renders the subprogram to
get executed for the other records as well.
it looks like, if there is heavy execution inside the subprogram,
the main program "forgets" about some data inside the loop.



More information about the freebsd-questions mailing list