bash zip 警告 - 名称不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46015202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:25:46  来源:igfitidea点击:

zip warning - name not matched

bashunixzip

提问by user2650277

I am getting the following error while using zip in my bash script

在 bash 脚本中使用 zip 时出现以下错误

zip warning: name not matched: test.png test2.png

zip warning: name not matched: test.png test2.png

#!/bin/bash
files_to_zip="test.png test2.png"
zipfile_name=result$(date "+%Y.%m.%d-%H.%M.%S").zip
zip "$zipfile_name"  "$files_to_zip"

Note: The images are in the same directory as the script and when i execute zip test.zip test.png test2.png, the zip get created just fine.

注意:图像与脚本位于同一目录中,当我执行时zip test.zip test.png test2.png,zip 创建得很好。

采纳答案by Artemy Vysotsky

When names are combined inside same quotes whole string is treated as file name. Use

当名称在相同的引号内组合时,整个字符串被视为文件名。用

zip "$zipfile_name" $files_to_zip

instead. And if your png names have special characters like spaces - add quotes or escape this characters inside the $files_to_zipvariable

反而。如果您的 png 名称具有特殊字符(如空格) - 在$files_to_zip变量中添加引号或转义此字符