How to disable the "zip" warning in bash?

I want to make a zip file using the bash shell, so I used:

echo -n 'Insert the file path:' read path echo 'Hello World' > ${path} zip -u ${path}.zip ${path} 

When I run this script, it gives me a warning:

 zip warning: test.zip not found or empty adding: test (deflated 66%) 

It works fine, but how can I turn off this warning? Am I using zip correctly?

+7
source share
4 answers

I think you need a quiet flag.

 zip -uq ${path}.zip ${path} 

From the man pages:

 -q --quiet Quiet mode; eliminate informational messages and comment prompts. (Useful, for example, in shell scripts and background tasks). 
+18
source

maybe you can try adding instead of updating (-u)?

on the man page:

  add Update existing entries and add new files. If the archive does not exist create it. This is the default mode. update (-u) Update existing entries if newer on the file system and add new files. If the archive does not exist issue warning then create a new archive. freshen (-f) Update existing entries of an archive if newer on the file system. Does not add new files to the archive. delete (-d) Select entries in an existing archive and delete them. 
+1
source

You should probably not specify zip to update the archive ( -u ). Without -u , the zip switch attempts to add files to the archive and should create non-existent archives without warning.

+1
source

You can also delete unwanted output lines and leave the normal status information visible, but first you need to redirect stderr to stdout. For example, the following command will extract only certain specific files from many zip files, but will not show emnpty lines and not complain about files not found. This way you still have some data for logging, debugging, etc.

 unzip -jn archivedlogfiles\* \*logfile\* 2>&1 | grep -vE '^$|^caution.*' Archive: archivedlogfiles1.zip inflating: little_logfile_20160515.log inflating: little_logfile_20160530.log Archive: archivedlogfiles2.zip Archive: archivedlogfiles3.zip Archive: archivedlogfiles4.zip Archive: archivedlogfiles5.zip Archive: archivedlogfiles6.zip Archive: archivedlogfiles7.zip Archive: archivedlogfiles8.zip inflating: little_logfile_20160615.log inflating: little_logfile_20160630.log Archive: archivedlogfiles9.zip 2 archives were successfully processed. 7 archives had fatal errors. 

Basically your command will look like this:

 zip -u ${path}.zip ${path} 2>&1 | grep vE '^zip\swarning.*' 
0
source

All Articles