From owner-freebsd-questions@FreeBSD.ORG Wed Aug 1 14:48:20 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E1FBE16A41B for ; Wed, 1 Aug 2007 14:48:20 +0000 (UTC) (envelope-from don.hinton@vanderbilt.edu) Received: from mailgate03.smtp.vanderbilt.edu (mailgate03.smtp.Vanderbilt.Edu [129.59.1.73]) by mx1.freebsd.org (Postfix) with ESMTP id AADB613C45B for ; Wed, 1 Aug 2007 14:48:20 +0000 (UTC) (envelope-from don.hinton@vanderbilt.edu) Received: from smtp09.smtp.vanderbilt.edu (smtp09.smtp.Vanderbilt.Edu [129.59.1.239]) by mailgate03.smtp.vanderbilt.edu (8.13.8/8.13.8) with ESMTP id l71Elo0I012095 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 1 Aug 2007 09:48:16 -0500 Received: from smtp09.smtp.vanderbilt.edu (localhost [127.0.0.1]) by smtp09.smtp.vanderbilt.edu (8.12.11/8.12.11/VU-3.7.9C+d3.7.9) with ESMTP id l71ElokG021790; Wed, 1 Aug 2007 09:47:50 -0500 (CDT) Received: from [192.168.0.2] (c-69-245-3-33.hsd1.tn.comcast.net [69.245.3.33]) by smtp09.smtp.vanderbilt.edu (8.12.11/8.12.11/VU-3.7.9.3B+d3.7.9) with ESMTP id l71ElkeQ021776 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 1 Aug 2007 09:47:50 -0500 (CDT) From: Don Hinton Organization: ISIS To: freebsd-questions@freebsd.org Date: Wed, 1 Aug 2007 09:47:44 -0500 User-Agent: KMail/1.9.7 References: <18096.39488.530454.883753@jerusalem.litteratus.org> In-Reply-To: <18096.39488.530454.883753@jerusalem.litteratus.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200708010947.45000.don.hinton@vanderbilt.edu> X-Proofpoint-Virus-Version: vendor=fsecure engine=4.65.5502:2.3.11, 1.2.37, 4.0.164 definitions=2007-08-01_06:2007-07-30, 2007-08-01, 2007-08-01 signatures=0 X-PPS: No, score=0 Cc: Robert Huff , questions@freebsd.org Subject: Re: semi OT: sh scripting problem 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: Wed, 01 Aug 2007 14:48:21 -0000 On Wednesday 01 August 2007 09:35:44 Robert Huff wrote: > (This is probably a FAQ, and I'll take a pointer (or even the > magic words to identify the problem) instead of an answer.) > Let's suppose I have a file FILE, with contents: > > foo > bar grill > baz > > If I do "cat FILE", everything comes out fine. > If, however, I write a script: > > > #!/bin/sh > > for i in `cat FILE` > do > . > . > . > . > done > > $i is set to > > foo > bar > grill > baz > > Is there a way within the script - or, failing that, by > modifying FILE - to not break at the whitespace? I'm sure someone will give you a more elegant solution, but short of using sed or awk (my preference), this might help: $ cat test.sh #!/bin/sh myloop() { while read line; do echo $line done } cat test.sh | myloop hth... don > > > Robert Huff > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "freebsd-questions-unsubscribe@freebsd.org" -- Don Hinton or Institute for Software Integrated Systems (ISIS), Vanderbilt University tel: 615.480.5667 or 615.870.9728