Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

zip warning - name not matched

Writer 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.

9

2 Answers

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

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.