Bash 解压捕获错误?

Bash 解压捕获错误?,bash,unzip,Bash,Unzip,偶尔,我们会收到供应商提供的似乎已损坏的ZIP文件。尝试列出ZIP的内容将触发如下错误: $>unzip -qql JABL_VER_20120808_165910.zip unzip: cannot find or open JABL_VER_20120808_165910.zip, JABL_VER_20120808_165910.zip.zip or JABL_VER_20120808_165910.zip.ZIP. 我快速阅读了解压手册页,并编写了代码片段以捕获上述错误

偶尔,我们会收到供应商提供的似乎已损坏的ZIP文件。尝试列出ZIP的内容将触发如下错误:

    $>unzip -qql JABL_VER_20120808_165910.zip
unzip:  cannot find or open JABL_VER_20120808_165910.zip, JABL_VER_20120808_165910.zip.zip or JABL_VER_20120808_165910.zip.ZIP.
我快速阅读了解压手册页,并编写了代码片段以捕获上述错误

EXIT=`echo $?`
case $EXIT in
> 0-1) echo "Unzip Complete.";;
> *) echo "Unzip Failed.";;
> esac
$>Unzip Failed.
它似乎起作用了。但是,在这种情况下,错误是不同的:

$>unzip -qql JABL_VER_20120808_175915.zip
  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:  cannot find zipfile directory in one of JABL_VER_20120808_175915.zip or
        JABL_VER_20120808_175915.zip.zip, and cannot find JABL_VER_20120808_175915.zip.ZIP, period.
有没有一种“可靠”的方法来捕捉这样的错误


PS:不确定是否重要,但ZIP文件是在MS Windows上生成的;我们使用红帽。

退出代码1也不好, 1遇到一个或多个警告错误,但处理仍然成功完成。这包括拉链 由于不支持的压缩方法或未知密码的加密,跳过了一个或多个文件

你应该试试

   unzip -t zipfilename
并且只接受退出代码0


为什么你会有这么多的错误?ftp文件处于文本模式?

退出代码1也不好, 1遇到一个或多个警告错误,但处理仍然成功完成。这包括拉链 由于不支持的压缩方法或未知密码的加密,跳过了一个或多个文件

你应该试试

   unzip -t zipfilename
并且只接受退出代码0


为什么你会有这么多的错误?在文本模式下ftp文件?

为什么您的代码不能处理该输出?返回代码是意外的0还是1?请在[01]中尝试
case$EXIT;*);;esac
祝你好运。为什么你的代码不能处理这个输出?返回代码是意外的0还是1?请在[01]中尝试
case$EXIT;*);;esac
祝你好运。通常一天,我们会从供应商那里收到大约400个拉链。“坏”拉链的比例非常小。约0.5%。我们已经要求他们调查根本原因,但与此同时,我需要对其进行处理,并在发生这种情况时向供应商发送电子邮件通知。添加了
unzip-tqq zipfilename
并在
case()
语句中检查返回值在一个典型的日子里,我们从供应商那里收到大约400个拉链。“坏”拉链的比例非常小。约0.5%。我们已经要求他们调查根本原因,但与此同时,我需要对其进行处理,并在发生这种情况时向供应商发送电子邮件通知。在
case()
语句中添加了
unzip-tqq-zipfilename
并检查了返回值