From owner-freebsd-questions@FreeBSD.ORG Fri Oct 14 20:09:09 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org 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 E9EC316A420 for ; Fri, 14 Oct 2005 20:09:08 +0000 (GMT) (envelope-from drew@mykitchentable.net) Received: from relay04.roc.ny.frontiernet.net (relay04.roc.ny.frontiernet.net [66.133.182.167]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6862943D45 for ; Fri, 14 Oct 2005 20:09:08 +0000 (GMT) (envelope-from drew@mykitchentable.net) Received: from filter02.roc.ny.frontiernet.net (filter02.roc.ny.frontiernet.net [66.133.183.69]) by relay04.roc.ny.frontiernet.net (Postfix) with ESMTP id B377B35823F; Fri, 14 Oct 2005 20:09:07 +0000 (UTC) Received: from relay04.roc.ny.frontiernet.net ([66.133.182.167]) by filter02.roc.ny.frontiernet.net (filter02.roc.ny.frontiernet.net [66.133.183.69]) (amavisd-new, port 10024) with LMTP id 27928-05-6; Fri, 14 Oct 2005 20:09:07 +0000 (UTC) Received: from blacklamb.mykitchentable.net (67-51-164-214.dsl1.elk.ca.frontiernet.net [67.51.164.214]) by relay04.roc.ny.frontiernet.net (Postfix) with ESMTP id 4ED93358272; Fri, 14 Oct 2005 20:08:57 +0000 (UTC) Received: from [165.107.42.123] (unknown [165.107.42.123]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by blacklamb.mykitchentable.net (Postfix) with ESMTP id CBFEA1549FC; Fri, 14 Oct 2005 13:08:56 -0700 (PDT) Message-ID: <43500FE4.30809@mykitchentable.net> Date: Fri, 14 Oct 2005 13:07:00 -0700 From: Drew Tomlinson User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: David Kirchner References: <435007F3.8000106@mykitchentable.net> <35c231bf0510141252o506328d8qf68d80faa9c2330d@mail.gmail.com> In-Reply-To: <35c231bf0510141252o506328d8qf68d80faa9c2330d@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-2.3.2 (20050629) at filter02.roc.ny.frontiernet.net Cc: FreeBSD Questions Subject: Re: Help With 'for' Loop X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Oct 2005 20:09:09 -0000 On 10/14/2005 12:52 PM David Kirchner wrote: >On 10/14/05, Drew Tomlinson wrote: > > >>Sorry to be such a pest today. I'm working on a sh script that uses a >>for loop. To test, I've written the following: >> >>for i in `/usr/bin/find /multimedia/Pictures -iname "*.jpg" -or -iname >>"*.gif" -print` >> do >> echo -e "\n$i" >>done >> >>The first line 'find' returns is "/multimedia/Pictures/1998 >>Christmas/April01.JPG" >> >>Yet 'echo $i' only returns "/multimedia/Pictures/1998", stopping at the >>first space. Is it possible to get 'i' to represent the whole string >>that 'find' returns? If so, how? >> >> > >'while read i' will do what you want, but may cause issues with >programs that expect to be able to read from stdin within the loop. > >find $findstuff | while read i >do > echo $i >done > > Thank you for your reply. I just tried 'while read i' and it works in this context. I'll find out soon enough if I have the stdin trouble you mention. I don't think I will but I'm very new to script writing. What I am ultimately attempting is to recursively search a directory and then create symlinks with modified names in a new directory to files in the first directory. For example, the first file found is "/multimedia/Pictures/1998 Christmas/April01.JPG". After saving this string in 'i' (or maybe a more descriptive name), I want to manipulate the string to be "1998_Christmas-April01.JPG" and then issue 'ln -s "/multimedia/Pictures/1998 Christmas/April01.JPG" /newdir/1998_Christmas-April01.JPG'. I've fiddled a bit with 'sed' and think I can make it work but I'm sure I'll be back with more questions. :) >You can also try something like: > >find $findstuff -exec echo {} \; > >(where $findstuff is your -iname conditionals). {} is replaced by the >files or directories found by find, and \; is necessary to terminate >the -exec argument. > > Another good idea although I don't think this will work as well for my purpose. Thanks again, Drew -- Visit The Alchemist's Warehouse Magic Tricks, DVDs, Videos, Books, & More! http://www.alchemistswarehouse.com