A little Bash script to help you.

Matthew Graybosch matthew at starbreaker.net
Mon Aug 11 15:09:56 PDT 2003

On Mon, 2003-08-11 at 17:49, Constantine wrote:
> Hello!
> I am writing a script, which involves unzipping some files. I would have 
> to unzip 4 different zip-files from some directory, and I would need to 
> unzip them to the directory, which would have the same name in it as the 
> original zip-file, i.e. I would like to run something like "ls *.zip", 
> have each file name recorded in some variable, and do a loop like "unzip 
> $filename[$i] -d $filename[$i].unzipped/". Can someone help me with the 
> code? How can I put the results of a command to a variable?

The following assumes you have the bash port installed. Just change the
ARCHIVE_DIR variable to the full path of the directory in which you have
your zip files. Make sure to save this code to a file in "~/bin". I
suggest pasting the following code into "~/bin/munzip.sh".

Then type "chmod +x ~/bin/munzip.sh", then "rehash", and then


#!/usr/bin/env bash



# you don't need ls *.zip
for zip in *
	# just for diagnostics
	echo "$zip"
	# here's the command you want.
	unzip "$zip" -d "$zip.unzipped/"
exit 0


Matthew Graybosch
"If you take a stand on a dead empty hand, 
never let 'em see your cards." --Savatage

More information about the freebsd-questions mailing list