如何禁用“zip” bash 中发出警告?
我想使用 bash shell 压缩文件,所以我使用了:
echo -n 'Insert the file path:'
read path
echo 'Hello World' > ${path}
zip -u ${path}.zip ${path}
当我运行此脚本时,它给了我一个警告:
zip warning: test.zip not found or empty
adding: test (deflated 66%)
它工作得很好,但如何禁用此警告?我是否以正确的方式使用 zip
?
I want to zip a file using bash shell, so I used:
echo -n 'Insert the file path:'
read path
echo 'Hello World' > ${path}
zip -u ${path}.zip ${path}
When I run this script, it gives me a warning:
zip warning: test.zip not found or empty
adding: test (deflated 66%)
It works just fine but how can I disable this warning? Am I using zip
in right way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想你想要安静的旗帜。
从手册页:
I think you want the quiet flag.
From the man pages:
也许你可以尝试“add”而不是 update(-u) ?
来自手册页:
maybe you can try "add" instead of update(-u) ?
from man page:
也许您不应该告诉
zip
更新存档 (-u
)。如果没有-u
开关,zip
会尝试将文件添加到存档中,并且应该创建不存在的存档而不发出警告。Probably you should not tell
zip
to update an archive (-u
). Without the-u
switchzip
tries to add files to an archive, and should create non-existing archives without warnings.您还可以删除不必要的输出行并保留正常状态信息可见,但您首先需要将 stderr 重定向到 stdout。例如,以下命令将从许多 zip 文件中仅提取一些特定文件,但不会显示空行,也不会抱怨找不到文件。这样你仍然有一些用于日志记录、调试等的输出。
基本上你的命令将如下所示:
You can also remove unnecessary output lines and leave normal status info visible, but you first need to redirect the stderr to stdout. For example following command will extract from many zip files only some specific files, but will not show emnpty lines nor complain for not found files. In that way you still have some output for logging, debugging etc.
Basically your command would then look like this: