Bash, tar, and broken pipe

Paul Falstad pfalstad at phoenix.princeton.edu
Tue May 21 10:08:49 AEST 1991


byron at archone.tamu.edu (Byron Rakitzis) wrote:
>Heinz (heinz at cc.univie.ac.at) sent me some personal mail which I could
>not reply to (is there another address I could use to get mail to you,
>Heinz?). However, he raised an interesting point:
>
>Given a pipeline
>
>  foo | tar ft -
>
>it seems clear that tar must read to EOF in order to determine whether
>the tar file that foo writes has come to an end or not. Therefore a
>normal instance of
>
>  foo | tar ft -
>
>should not cause a pipe to break, since tar will always terminate after
>foo. I have no clue why tar is exiting prematurely. If anyone can shed
>light on the matter, I think Heinz and I would appreciate it. (Servus,
>Heinz!)

I don't know the tarfile format, since I don't have source, but let's see:

% ls a
b  c
% tar cvf foo a
a/
a/b
a/c
% tar tvf foo
drwxr-xr-x pfalstad/student 0 May 20 20:05 1991 a/
-rw-r--r-- pfalstad/student 29 May 20 20:05 1991 a/b
-rw-r--r-- pfalstad/student 29 May 20 20:05 1991 a/c
% ls -l foo
-rw-r--r--  1 pfalstad    10244 May 20 20:13 foo

(that's quite a big file for only 58 bytes of data.  Must be lots
 of padding at the end)

% cat /etc/motd /usr/dict/words >>foo
% tar tvf foo
drwxr-xr-x pfalstad/student 0 May 20 20:05 1991 a/
-rw-r--r-- pfalstad/student 29 May 20 20:05 1991 a/b
-rw-r--r-- pfalstad/student 29 May 20 20:05 1991 a/c
% man tar | sed -n 242,246p
     If there are multiple archive  files  on  a  tape,  each  is
     separated from the following one by an EOF marker.  tar does
     not read the EOF mark on the tape after it finishes  reading
     an  archive  file  because tar looks for a special header to
     decide when it has reached the end of the archive.   Now  if
% ...

--
Paul Falstad                     | 10 PRINT "PRINCETON CS"
pfalstad at phoenix.princeton.edu   | 20 GOTO 10



More information about the Comp.unix.shell mailing list