Skip to content

Instantly share code, notes, and snippets.

@milkfarm
Created August 27, 2017 18:58
Show Gist options
  • Save milkfarm/ded1a18cb233f2b329f8b10076e62b45 to your computer and use it in GitHub Desktop.
Save milkfarm/ded1a18cb233f2b329f8b10076e62b45 to your computer and use it in GitHub Desktop.
Unzip epub file into a directory of the same base name
#! /bin/bash
# =======================================================================
#
# Unzips epub file into a directory with the same basename.
# If the directory exists, abort.
#
# To invoke, type:
# $ epubopen.sh filename.epub
#
# =======================================================================
# Changelog
#----------------------------------------------------------------------
#
# v.0.1 (2017-08-27) by milkfarm
# - original version
# Functions
# -----------------------------------------------------------------------
error () {
echo "! Error: $*"
exit 1
}
# Parameters
# -----------------------------------------------------------------------
source=$1
base=`basename $source`
target=${base%%.*}
# Test
# -----------------------------------------------------------------------
if [ ! -f "$source" ]; then
error "File does not exist: $source"
fi
if [ -d "$target" ]; then
error "Directory already exists: $target"
fi
# Main
# -----------------------------------------------------------------------
mkdir -v "$target"
unzip -d "$target" "$source"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment