Date: Wed, 1 Aug 2007 09:47:44 -0500 From: Don Hinton <don.hinton@vanderbilt.edu> To: freebsd-questions@freebsd.org Cc: Robert Huff <roberthuff@rcn.com>, questions@freebsd.org Subject: Re: semi OT: sh scripting problem Message-ID: <200708010947.45000.don.hinton@vanderbilt.edu> In-Reply-To: <18096.39488.530454.883753@jerusalem.litteratus.org> References: <18096.39488.530454.883753@jerusalem.litteratus.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <don.hinton at vanderbilt.edu> or <hintonda at gmail.com> Institute for Software Integrated Systems (ISIS), Vanderbilt University tel: 615.480.5667 or 615.870.9728
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708010947.45000.don.hinton>