Created
August 27, 2017 18:58
-
-
Save milkfarm/ded1a18cb233f2b329f8b10076e62b45 to your computer and use it in GitHub Desktop.
Unzip epub file into a directory of the same base name
This file contains hidden or 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 | |
# ======================================================================= | |
# | |
# 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