M'sieur Toph' M'sieur Toph' - 2 months ago 7
Bash Question

Make `unzip` try to unzip files if they exist without failure if not

How to make unzip ignore the not found files ?

When I run

unzip myArchive.zip config/*
does not match any file within the archive, I got a return code 11.

Is it possible to make
try to unzip files if they exist without failure if not?
If so, how ?

I did not find any option in the unzip manual to turn it into a "shut up if you fail, bro!" mode.

Of course, I could do something like
unzip myArchive.zip config/* | true
but it looks really ugly to me.

Thanks for your help

EDIT : it has been identified as dupplicate. It could be. The other answer is very useful, but make the command ignore ALL errors. I expected an option/trick that simply skip unfound files quietly and let the command keep failing in other error cases (if the archive does not exist for instance).


As this exit status is reserved to this single error case you could maybe:

unzip myArchive.zip config/* || \
( e=$? && if [ $e -ne 11 ]; then exit $e; fi )