Search code examples
bashunixzip

zip warning - name not matched


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

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.


Solution

  • 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_zip variable