zip warning - name not matched
Andrew Mclaughlin
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.
2 Answers
When names are combined inside same quotes whole string is treated as file name. Use
zip "$zipfile_name" $files_to_zipinstead. And if your png names have special characters like spaces - add quotes or escape this characters inside the $files_to_zip variable
add this line before sorting the files in directory
IFS=$'\n'
files=($(ls | sort))This worked for me and handled for numbers, dashes, special characters in the input files that are being converting to the zip file