From owner-freebsd-questions Sun Oct 14 21:48: 6 2001 Delivered-To: freebsd-questions@freebsd.org Received: from mail8.carolina.rr.com (fe8.southeast.rr.com [24.93.67.55]) by hub.freebsd.org (Postfix) with ESMTP id 3ADF537B405 for ; Sun, 14 Oct 2001 21:48:01 -0700 (PDT) Received: from snafu.enterit.com ([66.57.159.198]) by mail8.carolina.rr.com with Microsoft SMTPSVC(5.5.1877.687.68); Mon, 15 Oct 2001 00:47:41 -0400 Message-Id: <5.1.0.14.0.20011015010540.02b65280@mail.enterit.com> X-Sender: jconner@enterit.com@mail.enterit.com X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Mon, 15 Oct 2001 01:10:59 -0400 To: From: Jim Conner Subject: Re: sh script question Cc: freebsd-questions@FreeBSD.ORG In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG This is an excellent question. One that I would resolve by the following: At 21:09 10.14.2001 -0400, doug@safeport.com wrote: >I want to read a file line-wise. The following: >_______________ >#!/bin/sh >USER="doug" >FILE="newuser.form" Good so far but I would go ahead and assign $File: FILE=${FILE:-1} >if [ ! -e $FILE ]; then > echo "File: $FILE not found" > exit 1 >fi Still good... >for Line in `cat $FILE`; do > echo $Line >done I prefer to do things like this for a line by line read without affecting the IFS env variable. while read -r line do echo $line done < $FILE That will work fine. Now, if you want to go the route you were above by affecting the IFS variable then you can set IFS like this: IFS="\n" for line in $(cat $FILE) do echo $FILE done Let me know what you end up choosing. BTW, I use ksh as my shell of choice for scripting. If sh doesn't understand the above substitution for IFS try ksh. - Jim >--------------- > >gives the file a field per read. The field delimiter being >blank/whitespace. The >obvious answer would seem to be "IFS=" but I can not figure out the >syntax or even if that is possible. > >Thanks for any pointers > >_____ >Douglas Denault >doug@safeport.com >Voice: 301-469-8766 > Fax: 301-469-0601 > > >To Unsubscribe: send mail to majordomo@FreeBSD.org >with "unsubscribe freebsd-questions" in the body of the message - Jim -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- http://www.perlmonks.org/index.pl?node_id=67861&lastnode_id=67861 -----BEGIN PERL GEEK CODE BLOCK----- ------BEGIN GEEK CODE BLOCK------ Version: 0.01 Version: 3.12 P++>*@$c?P6?R+++>++++@$M GIT/CM/J d++(--) s++:++ a- >++++$O!MA->++++E!> PU-->+++BD C++++(+) UB++++$L++++$S++++$ $C-@D!>++++(-)$S++++@$X?WP+>++++MO!>+++ P++(+)>+++++ L+++(++++)>+++++$ !E* +PP+++>++++n-CO?PO!o >++++G W++(+++) N+ o !K w--- PS---(-)@ PE >*(!)$A-->++++@$Ee---(-)Ev++uL++>*@$uB+ Y+>+++ PGP t+(+++)>+++@ 5- X++ R@ >*@$uS+>*@$uH+uo+w-@$m! tv+ b? DI-(+++) D+++(++) G(++++) ------END PERL GEEK CODE BLOCK------ ------END GEEK CODE BLOCK------ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message