Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable 'zip' warning in bash?

I want to zip a file using 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 just fine but how can I disable this warning? Am I using zip in right way?

like image 679
Eng.Fouad Avatar asked Oct 09 '11 20:10

Eng.Fouad


3 Answers

maybe you can try "add" instead of update(-u) ?

from 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.
like image 68
Kent Avatar answered Nov 11 '22 23:11

Kent


I think you want the 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).
like image 32
Gazler Avatar answered Nov 11 '22 22:11

Gazler


Probably you should not tell zip to update an archive (-u). Without the -u switch zip tries to add files to an archive, and should create non-existing archives without warnings.

like image 2
sth Avatar answered Nov 11 '22 22:11

sth