On Tue, May 02, 2006 at 08:52:18PM +0300, Maxim Vexler wrote:
> >Instead you can use subshell (tested) like this:
> >
> >(
> >    FLAG=any
> >    while [ $FLAG ]
> >    do
> >        cat /DVD-MOUNT-DIR/backup.img.gz.*
> >        echo "Please put next DVD and press Y + Enter" > /dev/tty
> >        echo "If there is none, press Enter only" > /dev/tty
> >        read FLAG < /dev/tty
> >    done
> >) | gunzip -c | dd of=/dev/hda1
> >
> 
> That was elegant, I learned from this.
> Thank you.
> 
> Now I ask myself how can bash hold that much data inside a subshell
> for later on piping it, all at once, into gunzip ?

Unix pipes aren't a temporary buffer, in which one program puts all its
output, finishes running, and another program then runs and reads from.

When you run 'prog1 | prog2', both run in parallel, having a small
buffer (IIRC in Linux one page = 4KB, not sure if tunable) into which
one program writes and the other reads. The writing program blocks when
the buffer is full and the reading one blocks when its empty. All this
is done by the OS, not the shell. Read, for example, 'info libc pipes',
also found e.g. here:
http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_14.html
-- 
Didi


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to