Advertisement
wyatt8740

unzip file to its own directory

Jan 25th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.80 KB | None | 0 0
  1. #! /bin/bash
  2. #this could be cleaner, but it makes a new dir, CD's into it, and unzips the zip file in there.
  3. #useful when people release windows programs.
  4. #wyatt ward 2014
  5. #USUAL "WITHOUT ANY WARRANTY IMPLIED OR OTHERWISE" THING HERE
  6. export INFILENAME=`echo "$@" | awk -F/ '$0=$NF'`
  7. export OUTPUTDIR=`echo "$INFILENAME" | sed 's/.zip//g'`
  8. echo "OUTPUTDIR is"
  9. echo "$OUTPUTDIR"
  10. export STARTINGDIR="$PWD"
  11. if [ -f "$1" ]
  12. then
  13.         echo "Found file."
  14.         mkdir "$OUTPUTDIR"
  15.         cd "$OUTPUTDIR"
  16.         if [ `echo "$1" | grep [/]` ]
  17.         then
  18.                 #echo "yeah, starts with a slash"
  19.                 unzip "$1"
  20.         else
  21.                 #echo "no slash"
  22.                 unzip "$STARTINGDIR/$1"
  23.         fi
  24. #        unzip "$1"
  25. else
  26.         echo "$1 not found. Sorry."
  27. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement