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?
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With