Bourn Shell Scripts that Produce Multiple Files
Mario Hoerich
lists at MHoerich.de
Tue Apr 5 16:06:12 PDT 2005
# Martin McCormick:
> I wrote a Bourn Shell script which has a while loop in it that
> reads a file line by line. The output of the script is supposed to go
> to a file with a different name for each iteration of the loop. This
> scheme is obviously a rotten idea because all the new files end up
> created, but quite empty. If I take out the > $newfilename.txt
> directive, I get the proper output at stdout so the only problem is
> with changing the file name in the middle of the game several times.
This sounds a bit like a truncation issue.
If you do something like
command1 > bar
# some code
command2 > bar
then the second redirect will truncate the file to 0 bytes
before redirecting the output from command2 into it.
Try using >> instead of >, as it appends to the file.
If this doesn't help, please post the script (or a simplified
version thereof). We're not clairvoyant, you know... :)
HTH,
Mario
More information about the freebsd-questions
mailing list