• Uncategorized

About linux : zip-command-behaving-differently-in-different-bash-scripts

Question Detail

I have 2 bash scripts that use a zip command but one script zip command gives the following error.

zip warning: name not matched: file1.txt file2.txt

This is the command that I am using in both scripts.

zip "${updates_zip}.patch.zip" $(ls)

I tried to print the directory’s contents and file1.txt and file2.txt exist but the zip command still gives the above error.
It seems in 1 script it considers file1.txt file2.txt 2 different files but in another script, it is considering file1.txt file2.txt a single file having a space char in the name. However, I am not enclosing file names in quotes. Both scripts have the zip command written in exactly the same way as mentioned above.

Question Answer

Your other script probably has IFS variable modified. Instead of using ls, just use filename expansion like the following.

zip "${updates_zip}.patch.zip" *.txt

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.