Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Apr 2005 01:06:06 +0200
From:      Mario Hoerich <lists@MHoerich.de>
To:        Martin McCormick <martin@dc.cis.okstate.edu>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Bourn Shell Scripts that Produce Multiple Files
Message-ID:  <20050405230605.GA93190@Pandora.MHoerich.de>
In-Reply-To: <200504052028.j35KSU9S042813@dc.cis.okstate.edu>
References:  <200504052028.j35KSU9S042813@dc.cis.okstate.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
# 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050405230605.GA93190>