2

I am using ksh

dummpy_file does not exist . Finding the exit status of tar

SUSE10 / tar version GNU 1.15.1

>gunzip -d dummpy_file | tar xvf -
gunzip : dummpy_file: No such file or directory
>echo $?
>0

SUSE11 / tar version GNU 1.20

>gunzip -d dummpy_file | tar xvf -
gunzip : dummpy_file No such file or directory   
tar : This does not look tar archive  
tar: Error exit delayed from previous errors  
>echo $?   
>2

Is the difference in behavior due the different tar versions ? Please help

1 Answers1

4

Yes, tar 1.19 fixed the following bug:

Recognition of broken archives.
When supplied an archive smaller than 512 bytes in reading mode (-x, -t), previous tar
versions silently ignored it, exiting with code 0. It is fixed. Tar now issues the
following diagnostic message: This does not look like a tar archive, and exits with code 2."

When the gunzip program at the start of pipeline can't find the file it's supposed to unpack, it exits and emits 0 bytes to its stdout. The old tar version behaved as if 0 bytes were a correct tar archive, hence no error message.

Michał Kosmulski
  • 9,855
  • 1
  • 32
  • 51
  • I tried the same test , now instead of non existant file , i used a text file which is around 1MB and rename to abc.tar.gz so that untaring fails . Now also gunzip -d abc.tar.gz | tar xvf - gunzip: abc.tar.gz : is not in gzip format > echo $? is giving 0 in the tar version 1.15 . Please tell me if this bug is also fixed in 1.19 ? – Preetham Shenoy Apr 12 '12 at 10:31
  • Yes, it's the same thing. The important thing is that the first program doesn't output anything to its standard output (the error message goes to standard error stream, which is separate). – Michał Kosmulski Apr 12 '12 at 10:40