user2650277
user2650277

Reputation: 6749

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.

Upvotes: 7

Views: 33641

Answers (2)

Prasanna kiran
Prasanna kiran

Reputation: 1

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

Upvotes: 0

Artemy Vysotsky
Artemy Vysotsky

Reputation: 2734

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

Upvotes: 8

Related Questions