在 bash 脚本中使用 zip 时出现以下错误
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"
Run Code Online (Sandbox Code Playgroud)
注意:图像与脚本位于同一目录中,当我执行时zip test.zip test.png test2.png,zip 会很好地创建。
当名称组合在相同的引号内时,整个字符串将被视为文件名。使用
zip "$zipfile_name" $files_to_zip
Run Code Online (Sandbox Code Playgroud)
反而。如果您的 png 名称包含空格等特殊字符 - 在$files_to_zip变量中添加引号或转义该字符