Created
January 2, 2018 22:10
-
-
Save AndrewBelt/2c8fbe4ca24231a147e348391fa747d6 to your computer and use it in GitHub Desktop.
Merges multiple ZIP files into a single ZIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
OUT_NAME="$1" | |
shift | |
IN_NAMES="$@" | |
TMP_DIR=$(mktemp -d) | |
# Unzip each input ZIP | |
for IN_NAME in $IN_NAMES; do | |
unzip -n "$IN_NAME" -d "$TMP_DIR" | |
done | |
# ZIP all contents of uncompressed output into the temporary directory | |
(cd "$TMP_DIR"; zip -r "$OUT_NAME" *) | |
# Move output ZIP to final location | |
mv "$TMP_DIR"/"$OUT_NAME" "$OUT_NAME" | |
# Check contents of output ZIP | |
unzip -l "$OUT_NAME" | |
# Clean up all temporary files | |
rm -r "$TMP_DIR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment