#! /bin/bash # ############################################################################# NAME_="unzip2dir" PURPOSE_="extract zip file to a dir of the same name as zip's prefix" SYNOPSIS_="$NAME_ [-vhlr] [file...]" REQUIRES_="standard GNU commands, unzip" VERSION_="1.1" DATE_="1999-08-28; last update: 2003-12-21" AUTHOR_="Dawid Michalczyk " URL_="www.comp.eonworks.com" CATEGORY_="compress" PLATFORM_="Linux" SHELL_="bash" DISTRIBUTE_="yes" # ############################################################################# # This program is distributed under the terms of the GNU General Public License usage () { echo >&2 "$NAME_ $VERSION_ - $PURPOSE_ Usage: $SYNOPSIS_ Requires: $REQUIRES_ Options: -r, remove the zip file after extraction -v, verbose -h, usage and options (help) -l, see this script" exit 2 } # args check [ $# -eq 0 ] && { echo missing argument, type $NAME_ -h for help; exit 2; } # var initializing rm_zip= verbose= # option and argument handling while getopts vhlr options; do case $options in r) rm_zip=on ;; v) verbose=on ;; h) usage ;; l) more $0; exit 2 ;; \?) echo invalid argument, type $NAME_ -h for help; exit 2 ;; esac done shift $(( $OPTIND - 1 )) # main script execution for a in "$@"; do case $a in *.[zZ][iI][pP]) [ -d ${a%.*} ] && echo "${NAME_}: skipping ${a%.*} such dir already exist, cannot extract to it" && continue mkdir ${a%.*} [[ $verbose ]] && echo "${NAME_}: extracting "$a unzip -qq $a -d ${a%.*} [[ $rm_zip ]] && rm -f -- $a ;; *) echo "${NAME_}: $a not a zip file or lacks a zip suffix" ;; esac done