Skip to content

Instantly share code, notes, and snippets.

@AndrewBelt
Created January 2, 2018 22:10
Show Gist options
  • Save AndrewBelt/2c8fbe4ca24231a147e348391fa747d6 to your computer and use it in GitHub Desktop.
Save AndrewBelt/2c8fbe4ca24231a147e348391fa747d6 to your computer and use it in GitHub Desktop.
Merges multiple ZIP files into a single ZIP
#!/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