Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Aug 2003 18:17:25 -0400
From:      Michael Conlen <meconlen@obfuscated.net>
To:        Constantine <cnst@rbcmail.ru>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: simple sh scripting. How to put a result of a command to a variable?
Message-ID:  <3F3815F5.5070302@obfuscated.net>
In-Reply-To: <3F380F5D.6020904@rbcmail.ru>
References:  <3F380F5D.6020904@rbcmail.ru>

next in thread | previous in thread | raw e-mail | index | archive | help

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





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3F3815F5.5070302>