From owner-freebsd-questions@FreeBSD.ORG Mon Aug 11 15:17:32 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 3746637B401 for ; Mon, 11 Aug 2003 15:17:32 -0700 (PDT) Received: from svaha.com (svaha.com [64.46.156.67]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4920A43F75 for ; Mon, 11 Aug 2003 15:17:31 -0700 (PDT) (envelope-from meconlen@obfuscated.net) Received: from obfuscated.net (internal.neutelligent.com [64.156.25.4]) (AUTH: LOGIN meconlen) by svaha.com with esmtp; Mon, 11 Aug 2003 18:17:29 -0400 Message-ID: <3F3815F5.5070302@obfuscated.net> Date: Mon, 11 Aug 2003 18:17:25 -0400 From: Michael Conlen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Constantine References: <3F380F5D.6020904@rbcmail.ru> In-Reply-To: <3F380F5D.6020904@rbcmail.ru> 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:17:32 -0000 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? 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