From owner-freebsd-questions@FreeBSD.ORG Fri Oct 14 19:52:06 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 64BB616A41F for ; Fri, 14 Oct 2005 19:52:06 +0000 (GMT) (envelope-from dpkirchner@gmail.com) Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.197]) by mx1.FreeBSD.org (Postfix) with ESMTP id 01E2B43D45 for ; Fri, 14 Oct 2005 19:52:05 +0000 (GMT) (envelope-from dpkirchner@gmail.com) Received: by xproxy.gmail.com with SMTP id t13so459767wxc for ; Fri, 14 Oct 2005 12:52:05 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=p0X8hDcQgXcaHBjQahoiV/5wfsWSZYUyh+VN79l1ah4sdoa2La0ihqDBiS9WKZPCATZNlOi4S/RS4wSmuy0HsDBpU9X+Jj+YGk0pG1q6ZAc9Kt5O6naIu52rQEnpgTEjTVYltca3mWIZ1F5MB3qncDC2dNoYJd9kM8oeBVEpKuk= Received: by 10.70.103.13 with SMTP id a13mr1399043wxc; Fri, 14 Oct 2005 12:52:05 -0700 (PDT) Received: by 10.70.104.20 with HTTP; Fri, 14 Oct 2005 12:52:05 -0700 (PDT) Message-ID: <35c231bf0510141252o506328d8qf68d80faa9c2330d@mail.gmail.com> Date: Fri, 14 Oct 2005 12:52:05 -0700 From: David Kirchner Sender: dpkirchner@gmail.com To: Drew Tomlinson In-Reply-To: <435007F3.8000106@mykitchentable.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <435007F3.8000106@mykitchentable.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 19:52:06 -0000 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 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.