Re: [bash] [redirection] appending using a file descriptor

From: claudibus (sick_soul_at_yahoo.it)
Date: 09/29/03


Date: 29 Sep 2003 02:41:29 -0700


> claudibus wrote:
> > I'm trying to append data to a file in bash using only an already open
> > file descriptor.
> >
> > example (supposing file descriptor 5 is already open)
> >
> > cat FILE >&5
> >
> > works ok, but overwrites the file instead of just appending. So I
> > guessed
> [...]
>
> That's « exec 5> some-file » that overwrites the file (at this
> stage it truncates it to zero size).
>
> Change it to « exec 5>> some-file ».
[cut]

No, the point is I don't have the filename of the target. I have the
shell opened as a child process of a program, having the file
descriptor n corresponding to target file already open for writing.
Now I would like the stdout of the shell redirected to file descriptor
n in append mode, NOT the file descriptor n redirected in append mode
to some-filename.

/* code example starts */

extern char* qs; /* a temporary string buffer */

void printheader(FILE* target) {
  fd = fileno(target);
  sprintf(qs, "date -I >&%i", fd); /* this is ok, but overwrites.
*/
  system(qs); /* would like to append instead
*/
}

/* code example ends */

Claudio