From owner-freebsd-questions@FreeBSD.ORG Mon Aug 11 15:35:34 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 4ACD637B401 for ; Mon, 11 Aug 2003 15:35:34 -0700 (PDT) Received: from hawk.mail.pas.earthlink.net (hawk.mail.pas.earthlink.net [207.217.120.22]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9A2B843F75 for ; Mon, 11 Aug 2003 15:35:33 -0700 (PDT) (envelope-from cnst@rbcmail.ru) Received: from user236.net406.nc.sprint-hsd.net ([65.40.91.236] helo=rbcmail.ru) by hawk.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 19mLGB-00070u-00; Mon, 11 Aug 2003 15:35:27 -0700 Message-ID: <3F381A25.3050901@rbcmail.ru> Date: Mon, 11 Aug 2003 18:35:17 -0400 From: Constantine User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.4) Gecko/20030624 X-Accept-Language: en-gb, ru, en-us, en MIME-Version: 1.0 To: Michael Conlen References: <3F380F5D.6020904@rbcmail.ru> <3F3815F5.5070302@obfuscated.net> In-Reply-To: <3F3815F5.5070302@obfuscated.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-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: Mon, 11 Aug 2003 22:35:34 -0000 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? Cheers, Constantine.