Unzipping the empty file sends a non Zero return code

Hi,

I have a shell script where I am trying to unzip bunch of files zip files one by one. But out of many zip files, if any one zip file is empty, the unzip command sends a non-zero return code and fails the script.

I am trying to see if I can get a success error code even if the script tries to unzip an empty zip file.

sample code snipet
 
cd  DIR1
for zipfilename in `cat /DIR2/$zipfilename.txt`
do
cp zipfilename /tmp/.
unzip -n zipfilename 
rc=$?
 
if $rc != 0 then 
echo "Process fail"
fi
 

Hello,

Following is the example for checking the zero and non-zero size zip files.

$ cat check_gz.ksh
find . -name "*.gz" | sed 's/\.\///g' > /tmp/checkcheck1211
while read line
do
if [[ -s $line ]]
then
echo $line "File is non-zero size"
else
echo $line "File is zero size"
fi
 
done < "/tmp/checkcheck1211"

In place of echo we can put the appropriate commands or conditions as per your requirement please.

Thanks,
R. Singh

Are you trying to unzip a zero byte file? That is not a zipped file. A zero byte file that has been zipped has a size:-

$ touch robin
$ zip -r robin robin
  adding: robin (stored 0%)
$ ls -l
total 4
-rw-r--r-- 1 batterra techsupp   0 Jan 16 13:45 robin
-rw-r--r-- 1 batterra techsupp 160 Jan 16 13:45 robin.zip
$ unzip -p robin    
[robin]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
$ unzip -p robin.zip
$ 

There is no output from the final command because the original file is empty.

I hope that this helps,
Robin
Liverpool/Blackburn
UK