From owner-freebsd-questions@FreeBSD.ORG Mon Aug 11 15:09:56 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6CE0637B401 for ; Mon, 11 Aug 2003 15:09:56 -0700 (PDT) Received: from mail-da-1.dns-solutions.net (unknown [69.12.117.4]) by mx1.FreeBSD.org (Postfix) with SMTP id 685B443F93 for ; Mon, 11 Aug 2003 15:09:55 -0700 (PDT) (envelope-from matthew@starbreaker.net) Received: (qmail 46124 invoked from network); 11 Aug 2003 22:09:54 -0000 Received: from unknown (HELO ?209.113.232.22?) (matthew@starbreaker.net@209.113.232.22) by mail-da-1.dns-solutions.net - 209.113.232.22 with SMTP; 11 Aug 2003 22:09:54 -0000 From: Matthew Graybosch To: FreeBSD Questions In-Reply-To: <3F380F5D.6020904@rbcmail.ru> References: <3F380F5D.6020904@rbcmail.ru> Content-Type: text/plain Organization: starbreaker.net Message-Id: <1060639888.14212.35.camel@christabel.starbreaker.net> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.3 Date: 11 Aug 2003 18:11:28 -0400 Content-Transfer-Encoding: 7bit Subject: A little Bash script to help you. X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: matthew@starbreaker.net List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2003 22:09:56 -0000 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 "munzip.sh". ************************************************************** #!/usr/bin/env bash ARCHIVE_DIR="~/archive" cd $ARCHIVE_DIR # you don't need ls *.zip for zip in * do # just for diagnostics echo "$zip" # here's the command you want. unzip "$zip" -d "$zip.unzipped/" done exit 0 ************************************************************** -- Matthew Graybosch http://www.starbreaker.net "If you take a stand on a dead empty hand, never let 'em see your cards." --Savatage