From owner-freebsd-questions@FreeBSD.ORG Mon Aug 11 18:09:42 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 8F91B37B401 for ; Mon, 11 Aug 2003 18:09:42 -0700 (PDT) Received: from webserver.get-linux.org (adsl-64-161-78-226.dsl.lsan03.pacbell.net [64.161.78.226]) by mx1.FreeBSD.org (Postfix) with SMTP id A30F443FAF for ; Mon, 11 Aug 2003 18:09:41 -0700 (PDT) (envelope-from root@webserver.get-linux.org) Received: (qmail 11065 invoked by uid 0); 12 Aug 2003 01:10:02 -0000 Date: Mon, 11 Aug 2003 18:10:02 -0700 From: Joshua Oreman To: Constantine Message-ID: <20030812011001.GA11055@webserver> References: <3F380F5D.6020904@rbcmail.ru> <3F3815F5.5070302@obfuscated.net> <3F381A25.3050901@rbcmail.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3F381A25.3050901@rbcmail.ru> User-Agent: Mutt/1.4.1i cc: questions@freebsd.org Subject: Re: simple sh scripting. How to put a result of a command to a variable? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2003 01:09:42 -0000 On Mon, Aug 11, 2003 at 06:35:17PM -0400 or thereabouts, Constantine wrote: > Michael Conlen wrote: > > >Constantine wrote: > > > >>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? > > > >If I understand you properly I think the following would do what you want > > > >#!/bin/sh > >for i in `ls *.zip` > >do > > unzip ${i} -d ${i}.unzipped > >done > > Thank you very much indeed! Seems just what I wanted. But can I save the > archive names in an array for further manipulation? Also, how can I type > that apostrophe ` from my keyboard? For the array I think you do need bash. I'm not familiar with arrays in shell; someone else may be able to help you there. As far as the backquote (`), it seems you answered your own question by typing it into your email. (But the backquote is on the tilde (~) key, if you don't push shift). -- Josh > > Cheers, > Constantine. > > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"