You're complicating it.
If zip
exits with an exit status that reflects success or failure, you can simply do
$ zip -r foo.zip . && mv foo.zip mydir && rm -rf *
However, I really hope mydir
is not located in the current directory, or it would get deleted by the rm -rf *
. In general when using rm -rf
, I'd think both two and three times before I put a *
after it!! In fact, I can count the number of times I've done that (rm -rf *
) in the last year on the fingers of one hand. I would never put it in a script.
Safer way (assuming mydir
is actually a path to somewhere else than in the current directory):
$ zip -r --move --test foo.zip . && mv foo.zip mydir
Or even
$ zip -r --move --test mydir/foo.zip .
Note the use of .
(dot) rather than *
. With *
any file with a -
as the first character in its name would be interpreted as a command line switch to zip
. Test this by creating a file called --encrypt
, for example:
$ touch -- --encrypt
$ zip -r --move --test ../test.zip *
Enter password:
$ rm -- --encrypt
mv
copies and then removes from the source location. You don't needrm
anymore. PS : please have a look at the difference between;
and&&
zip
andmv
in the background???echo $?
.