#!/bin/bash # Source - https://stackoverflow.com/a/7069755 # Posted by Flexo - Save the data dump, modified by community. See post 'Timeline' for change history # Retrieved 2026-06-20, License - CC BY-SA 4.0 while test $# -gt 0; do case "$1" in -h|--help) echo "catzip - cat out the contents of a file in a zipped file" echo " " echo "Usage:" echo " catzip -z zip-file -f file" echo " " echo "options:" echo "-h, --help Show this prompt" echo "-z, --zip-file The compressed file to browse into" echo "-f, --file The file within the compressed file to cat" exit 0 ;; -z|--zip-file) shift if test $# -gt 0; then export ZIP=$1 else echo "No zip file specified!" exit 1 fi shift ;; -f|--file) shift if test $# -gt 0; then export FILE=$1 else echo "No file file specified!" exit 1 fi shift ;; *) if test -z "$ZIP"; then export ZIP=$1 shift elif test -z "$FILE"; then export FILE=$1 shift else echo "Too many arguments provided!" exit 1 fi ;; esac done if test -z "$ZIP"; then echo "Zip file is required!" exit 1 fi if test -z "$FILE"; then echo "File is required!" exit 1 fi # Set up the python environment if [ ! -f "/tmp/shell-scripts/venv/bin/python" ]; then mkdir -p /tmp/shell-scripts python3 -m venv /tmp/shell-scripts/venv > /dev/null 2>&1 fi # Finally run the script /tmp/shell-scripts/venv/bin/python << EOF from zipfile import ZipFile zip_file="$ZIP" file="$FILE" with ZipFile(zip_file, "r") as zip: with zip.open(file) as file: print(file.read().decode()) EOF